Inside my plugin specific function, i would like to test the ID of my coupon code.
If the coupon used by the customer is this ID do this ... else do this ...
I never develop with the woocommerce set-up and this need is realy simple.
Could you help me ?
Here is my function :
Note : sg_enable_order_approval == enable means All order is need admin approval sg_enable_order_approval == disable means enable plugin for per product
function sgitsoa_paymentgatways_disable_manager( $available_gateways )
{
global $woocommerce;
$allowed_gateways = array();
$sg_product_enable = false;
if(is_admin()) {
return $available_gateways;
}
// check cart for any product which enable product approval
if(get_option('sg_enable_order_approval')=='disable' ) { // plugin activate for per product
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
$_product = wc_get_product($values['data']->get_id());
if(get_post_meta($values['product_id'], 'sg_product_enable', true)=='yes') {
$sg_product_enable = true;
}
}
}
// Check all products in cart. If any of the product require confirmation please make order approval.
if(get_option('sg_enable_order_approval')=='enable' || $sg_product_enable==true ) {
if(is_checkout() && isset($available_gateways['sgitsoa_gateway']) && !is_wc_endpoint_url('order-pay') ) {
$allowed_gateways['sgitsoa_gateway'] = $available_gateways['sgitsoa_gateway'];
return $allowed_gateways;
}
if(is_wc_endpoint_url('order-pay') && isset($available_gateways['sgitsoa_gateway']) ) {
unset($available_gateways['sgitsoa_gateway']);
return $available_gateways;
}
}
//
if($sg_product_enable==false) {
unset($available_gateways['sgitsoa_gateway']);
}
return $available_gateways;
}
}
'''
Aucun commentaire:
Enregistrer un commentaire