WooCommerce前台价格库存号前台实时更新

  • Comments Off on WooCommerce前台价格库存号前台实时更新
  • 252
  • 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>' ) ) : '';
weinxin
独角兽驿站
公众号