- A+
所属分类:WordPress插件
1 主题functions.php
文件添加变量产品判断
//mufeng add for display variation sku
add_action( 'woocommerce_after_add_to_cart_form', 'mufeng_echo_variation_info' );
function mufeng_echo_variation_info() {
global $product;
if ( ! $product->is_type( 'variable' ) ) return;
wc_enqueue_js( "
$(document).on('found_variation', 'form.cart', function( event, variation ) {
$('.mufeng_variation_sku').html(variation.sku); // SIMPLY CHANGE sku INTO ONE OF THE KEYS BELOW
});
" );
}
//mufeng add for display variation variation price
add_action( 'woocommerce_variable_add_to_cart', 'bbloomer_update_price_with_variation_price' );
function bbloomer_update_price_with_variation_price() {
global $product;
$price = $product->get_price_html();
wc_enqueue_js( "
$(document).on('found_variation', 'form.cart', function( event, variation ) {
if(variation.price_html) $('.summary > p.price').html(variation.price_html);
$('.woocommerce-variation-price').hide();
});
$(document).on('hide_variation', 'form.cart', function( event, variation ) {
$('.summary > p.price').html('" . $price . "');
});
" );
}
2 产品页添加库存号标签和容器。
Woocommerce插件目录templates/single_product/add-to-cart/variable.php
第38行,td内添加label
换行。
<br><br><label>库存号</label>
第48行,把重置规格链接改为p标签,显示库存号。
echo end( $attribute_keys ) === $attribute_name ? wp_kses_post( apply_filters( 'woocommerce_reset_variations_link', '<p class="mufeng_variation_sku"></p>' ) ) : '';
独角兽驿站
公众号