在woocommerce_init钩子中获取购物车中的应用优惠券

时间:2016-10-20 15:03:27

标签: php woocommerce hook-woocommerce

我正在尝试在woocommerce_init下获得按顺序使用的优惠券。试图查看数组$ GLBALS并发现smth相关但不知道如何访问它们。

function remove_email_for_testcop_coupon($order_id) {
    global $woocommerce;
    $coupons = $woocommerce->cart->applied_coupons;
    var_dump($GLOBALS['GLOBALS']['wp_filter']['init']); //=> here there are found but don't know how to access it normaly =>  need to reach applied_coupons, just that is generating a dinamic nonce.
    remove_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
    if (in_array('testcop', $coupons)) {
        remove_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
    }
}
//add_action('wp', 'remove_email_for_testcop_coupon');
add_action( 'woocommerce_init', 'remove_email_for_testcop_coupon');

1 个答案:

答案 0 :(得分:0)

管理以了解具体方法:

function remove_email_for_testcop_coupon($order_id) {
    global $wp;
    $coupons = array();
    $cpage = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    if (strpos($cpage, '/course/') === false) {
        $obj = new WC_Session_Handler();
        $data =  accessProtected($obj, '_data');
        $coupons = unserialize($data['applied_coupons']);
        if (!empty($coupons)) {
            if (in_array('masterkey', $coupons) || in_array('testcop', $coupons)) {
                remove_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
            }
        }
    }
}
add_action( 'woocommerce_init', 'remove_email_for_testcop_coupon');