我正在尝试在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');
答案 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');