Show default variation price Woocommerce, hiển thị giá mặc định của biến thể như thế nào mọi người? Em có cái web wordpress có nhiều biến thể, em muốn ở ngoài nó sẽ hiện giá mặc định của biến thể Default được chọn trong sản phẩm cho người dùng thấy ở ngoài danh sách sản phẩm và bên trong chi tiết sản phẩm lun. Hiện tại em dùng biến thế thì nó hiển thị mức giá của biến thể đó, em muốn bỏ nó đi hiển thị giá mặc định thì làm như thế nào? Ngoài danh sách sản phẩm, muốn xóa giá trong khoảng đi, thay vào giá mặc đinh.
Của em đây nhé, chèn code sau vào tập tin function.php của themes nhé. Mã: // show default variation price add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2); function custom_variation_price( $price, $product ) { $default_attributes = $product->get_variation_default_attributes(); foreach($product->get_available_variations() as $variation) { $is_default=true; foreach($default_attributes as $attribute_key => $attribute_value) { if($variation['attributes']['attribute_' . $attribute_key] != $attribute_value){ $is_default=false; break; } } if($is_default){ return $variation['price_html']; } } }