Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. do_action( 'woocommerce_shipping_method_chosen', 'check_if_dhl', 10, 1 );
  2.  
  3. function check_if_dhl( $chosen_method ) {
  4.     global $woocommerce;
  5.  
  6.     $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
  7.     $chosen_shipping_no_ajax = get_shipping_name_by_id($chosen_methods[0]);
  8.  
  9.     if (strpos($chosen_shipping_no_ajax, 'DHL') !== false) {
  10.         // 184 is the product ID of the box package
  11.         WC()->cart->add_to_cart( 184 );
  12.     } else {
  13.         // A function I wrote to simplify removing of a product from cart.
  14.         remove_product_from_cart( 184 );
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement