2016-10-20 1 views
1

woocommerce_init에서 사용 된 쿠폰을 주문하려고합니다. $ GLBALS 배열을 보려고 시도했지만 관련성이 있음을 발견했지만 접근 방법을 모른다.woocommerce_init 후크의 장바구니에 쿠폰을 적용하는 방법

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'); 
:
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'); 

답변

관련 문제