我想在用户单击woocommerce上的添加到购物车时添加弹出确认

时间:2018-08-30 10:21:26

标签: php wordpress woocommerce

基本上,我想在用户单击单个产品页面上的“添加到购物车”按钮时显示弹出确认。仅当产品库存不足时,才会显示弹出窗口。通知用户该产品可以重新订购,需要2-3周的时间才能提供。如果用户单击弹出窗口中的“继续”按钮,则应将产品添加到购物车。

我在下面尝试了此代码,但无法正常工作:

function add_the_validation( $passed ) {
    if ( $product->managing_stock()) {

        $currentStockQuantity  = $product->get_stock_quantity(); 
        $minStockLevel =    get_post_meta( get_the_ID(), 'minimum_stock_level', true );

        if( ! empty( $minStockLevel ) ) {

            if($currentStockQuantity < $minStockLevel)
            {
                wc_add_notice( __( ' <div id="stock-popup" class="my-overlay">
                    <div class="my-popup" >
                        <a class="close" href="#stock-popup">×</a>
                        <div class="content">
                            Currently it is out of stock. If you want to order this product we will restore within 7 to 15days. If YES please continue Add to Cart.<br>
                            <form action="" method="POST">
                             <input class="popup-button" type="submit" value="1" name="continue_add_to_cart">
                             <input class="popup-button" type="submit" value="1" name="cancel">
                            </form>
                        </div>
                    </div>
                </div>', 'woocommerce' ), 'error' );
            }
        }

    }
    return $passed;
}
add_action( 'woocommerce_add_to_cart_validation', 'add_the_validation', 10, 5 );

0 个答案:

没有答案