我在我的eCommerce站点中使用的是WooCommerce的最新版本。
但是现在我想检查一下click AddToCart按钮当前的产品是否有向上销售。如果是,那么alert("Upsell available");,如果不是,那么简单的AddToCart操作将会工作,goto cart也会工作。
我不确定这里的条件是什么。我也不知道哪个地方需要创造条件,或者哪个地方是更好的选择。
发布于 2015-01-09 13:13:53
将以下代码添加到主题的functions.php中:
add_action( 'woocommerce_after_single_product_summary', 'custom_wc_upsell_rohil_display', 15 );
if (!function_exists('custom_wc_upsell_rohil_display')) {
function custom_wc_upsell_rohil_display() {
global $product;
$upsells = $product->get_upsells();
if($upsells){
wp_enqueue_script( 'frontend-custom', get_template_directory_uri() . '/js/frontend-custom.js', array("jquery"));
}
}
}现在创建一个.js文件,将其命名为frontend-custom.js并将其保存到wp-content > themes > your current theme > js中(因此js将存储在wp-content > themes > your-current-theme > js > frontend-custom.js中),并在该js文件中添加以下代码:
jQuery(document).ready(function($) {
$(".single_add_to_cart_button").click(function(){
alert("Up sell available");
});
});这是it.Now当任何产品有任何追加销售时,用户将点击add to cart按钮,alert将弹出,然后他们将重定向到购物车。
注意:它只能在Single Product页面上工作。
https://stackoverflow.com/questions/27853236
复制相似问题