Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Aelia Prices by Country customisation.
- * Makes all products unavailable for a specific region.
- *
- * NOTE
- * Customisations, such as this one, are outside the scope of Aelia's support
- * service. If you need assistance to implement, or alter this custom code,
- * you can hire us on Codeable: http://bit.ly/codeable_discount_new
- *
- * @param bool purchasable The original "purchasable" flag.
- * @param WC_Product product The product to process.
- * @return bool
- * @author Aelia
- */
- add_filter('woocommerce_is_purchasable', function($purchasable, $product) {
- // Get the instance of the Prices by Country plugin
- $pbc = \Aelia\WC\PricesByCountry\WC_Aelia_Prices_By_Country::instance();
- // Get the ID of the region to which customer's country belongs
- $region_id = $pbc->settings_controller()->get_region_for_country($pbc->get_customer_country());
- // Find the region ID from WooCommerce > Prices by Country settings page
- // Example: http://prntscr.com/cvxfg6
- $disabled_region_id = '<region ID here>';
- if($region_id === $disabled_region_id) {
- $purchasable = false;
- }
- return $purchasable;
- }, 50, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement