Advertisement
businessdad

Prices by Country - Make products unavailable for a region

Oct 18th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Aelia Prices by Country customisation.
  4.  * Makes all products unavailable for a specific region.
  5.  *
  6.  * NOTE
  7.  * Customisations, such as this one, are outside the scope of Aelia's support
  8.  * service. If you need assistance to implement, or alter this custom code,
  9.  * you can hire us on Codeable: http://bit.ly/codeable_discount_new
  10.  *
  11.  * @param bool purchasable The original "purchasable" flag.
  12.  * @param WC_Product product The product to process.
  13.  * @return bool
  14.  * @author Aelia
  15.  */
  16. add_filter('woocommerce_is_purchasable', function($purchasable, $product) {
  17.   // Get the instance of the Prices by Country plugin
  18.   $pbc = \Aelia\WC\PricesByCountry\WC_Aelia_Prices_By_Country::instance();
  19.   // Get the ID of the region to which customer's country belongs
  20.   $region_id = $pbc->settings_controller()->get_region_for_country($pbc->get_customer_country());
  21.  
  22.   // Find the region ID from WooCommerce > Prices by Country settings page
  23.   // Example: http://prntscr.com/cvxfg6
  24.   $disabled_region_id = '<region ID here>';
  25.  
  26.   if($region_id === $disabled_region_id) {
  27.     $purchasable = false;
  28.   }
  29.   return $purchasable;
  30. }, 50, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement