【发布时间】:2018-05-20 19:31:03
【问题描述】:
在我的 Woocommerce Shop 中,我使用以下代码在存档页面上的添加到购物车按钮旁边添加了一个数量框:
add_filter( 'woocommerce_loop_add_to_cart_link', 'quantity_inputs_for_woocommerce_loop_add_to_cart_link', 10, 2 );
function quantity_inputs_for_woocommerce_loop_add_to_cart_link( $html, $product ) {
if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
$html = '<a rel="nofollow" data-product_id="'. $product->id .'" onclick="addToCartLink(this,' . $product->id .')" class="add_to_cart_button product_type_simple button primary is-flat mb-0 is-small">הוסף לסל</a>';
// $html = '<a onclick="addToCartLink(this,'. $product->id .')">הוסף לסל</a>';
$html .= '<div class="quantity buttons_added">';
$html .= '<input type="button" value="-" class="minus button is-form">';
$html .= '<input type="number" id="quantity_'. $product->id .'" class="input-text qty text" step="1" min="0" max="9999" name="quantity" value="1" title="כמות" size="4" pattern="[0-9]*" inputmode="numeric" >';
$html .= '<input type="button" value="+" class="plus button is-form">';
$html .= '</div>';
}
return $html;
}
在购物车页面中,我创建了一个自定义交叉销售产品轮播。所以我需要避免这段代码在购物车页面中工作,所以交叉销售产品添加到购物车按钮将是默认的 woocommerce 按钮 .
如何在我的代码中排除购物车页面?
【问题讨论】:
标签: php wordpress woocommerce cart product