Code thêm giá tiết kiệm, giá Sale và giá bán trong woocommerce

5/5 - (1 bình chọn)

Zubi Cloud sẽ hướng dẫn cách Code thêm giá tiết kiệm, giá Sale và giá bán trong woocommerce.
Hãy xem hình minh họa về phần giá của chúng tôi. woocommerce price amount

gia sale wp

Rất đơn giản, hãy thêm đoạn code sau vào trong file functions.php của theme bạn đang dùng

add_filter( 'woocommerce_get_price_html', 'bbloomer_simple_product_price_format', 10, 2 );

function bbloomer_simple_product_price_format( $price, $product ) {
   
   if ( $product->is_on_sale() && $product->is_type('simple') ) {
      $price = sprintf( __( '<div class="web5c-was-now-save"><div class="web5c-was">%1$s</div><div class="web5c-now">%2$s</div><div class="web5c-save">Tiết kiệm: %3$s</div></div>', 'woocommerce' ), wc_price ( $product->get_regular_price() ), wc_price( $product->get_sale_price() ), wc_price( $product->get_regular_price() - $product->get_sale_price() )  );     
   }
   
   return $price;
}
5/5 - (1 bình chọn)


Trả lời