可变产品的“添加到购物车”功能而不是“选择选项”按钮行为

伍商务在产品循环中有两种按钮类型

  • “添加到购物车”,用于将简单产品添加到购物车

  • “选择选项”,如果一个简单的产品成为变量,或者添加了订阅选项。


我的设置:

所有Woo商业产品都使用以下插件同时配置为简单产品和订阅产品

  • “伍商业订阅”

  • “所有产品为伍康订阅”.默认值设置为简单产品。

现在,所有产品上的按钮都从“添加到购物车”更改为“选择选项”。这是伍商业的默认行为。


我的问题:

如何保留“添加到购物车”按钮及其将简单产品添加到购物车的功能,尽管产品可变?

其背后的逻辑:用户有机会在结账时做出选择,因此可以添加到购物车功能,而不是重定向到单个产品页面以进行选择。


叮当猫咪
浏览 202回答 2
2回答

杨魅力

您可以使用:(通过代码中添加的注释标签进行解释)function filter_woocommerce_loop_add_to_cart_link( $args, $product ) {&nbsp; &nbsp; // Shop page & product type = simple&nbsp; &nbsp; if ( is_shop() && $product->product_type === 'simple' ) {&nbsp; &nbsp; &nbsp; &nbsp; // Get product ID, sku & add to cart url&nbsp; &nbsp; &nbsp; &nbsp; $product_id = $product->get_id();&nbsp; &nbsp; &nbsp; &nbsp; $product_sku = $product->get_sku();&nbsp; &nbsp; &nbsp; &nbsp; $product_url = $product->add_to_cart_url();&nbsp; &nbsp; &nbsp; &nbsp; // Quantity & text&nbsp; &nbsp; &nbsp; &nbsp; $quantity = isset( $args['quantity'] ) ? $args['quantity'] : 1;&nbsp; &nbsp; &nbsp; &nbsp; $text = $product->add_to_cart_text();&nbsp; &nbsp; &nbsp; &nbsp; $args = '<a rel="nofollow" href="' . $product_url . '" data-quantity="' . $quantity . '" data-product_id="' . $product_id . '" data-product_sku="' . $product_sku . '" class="button product_type_simple add_to_cart_button ajax_add_to_cart add-to-cart" aria-label="Add to cart"><em>' . $text . '</em></a>';&nbsp; &nbsp; }&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return $args;&nbsp;}add_filter( 'woocommerce_loop_add_to_cart_link', 'filter_woocommerce_loop_add_to_cart_link', 10, 2 );

慕丝7291255

function filter_woocommerce_loop_add_to_cart_link( $link, $product ) {&nbsp; &nbsp; if ( is_shop() && $product->product_type === 'simple' ) {&nbsp; &nbsp; &nbsp; &nbsp; $product_id = $product->get_id();&nbsp; &nbsp; &nbsp; &nbsp; $product_sku = $product->get_sku();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $link = '<a rel="nofollow" href="?add-to-cart=' . $product_id . '" data-quantity="1" data-product_id="' . $product_id . '" data-product_sku="' . $product_sku . '" class="button product_type_simple add_to_cart_button ajax_add_to_cart add-to-cart" aria-label="Add to cart"><em>Add to cart</em></a>';&nbsp; &nbsp; }&nbsp; &nbsp; return $link;&nbsp;}add_filter( 'woocommerce_loop_add_to_cart_link', 'filter_woocommerce_loop_add_to_cart_link', 10, 2 );
打开App,查看更多内容
随时随地看视频慕课网APP