businessdad icon

WooCommerce Currency Switcher - Skip product conversion

businessdad | PRO | 11/10/16 05:38:04 PM UTC | 0 ⭐ | 925 👁️ | Never ⏰ | []
PHP |

1.17 KB

|

None

|

0 👍

/

0 👎

/**
 * Dummy method to suppress the "unsupported product" warning. This method
 * leaves the product untouched, without performing any conversion.
 *
 * @param WC_Product product A product instance.
 * @param string currency The target currency.
 * @return WC_Product
 * @author Aelia <[email protected]>
 * @link https://aelia.co
 */
function aelia_skip_product_conversion($product, $currency) {
  return $product;
}
 
/**
 * Replace the conversion callback with a custom one for specific product types.
 *
 * Need help customising the code for your need? Hire us on Codeable: http://bit.ly/codeable_aelia
 *
 * @param callable convert_callback A callback function, or method.
 * @param WC_Product product A product.
 * @return callable A callback function, or method.
 * @author Aelia <[email protected]>
 * @link https://aelia.co
 */
add_filter('wc_aelia_currencyswitcher_product_convert_callback', function($convert_callback, $product) {
  // Skip conversion for products with type "accommodation-booking"
  if($product->product_type === 'accommodation-booking') {
    $convert_callback = 'aelia_skip_product_conversion';
  }
  return $convert_callback;
}, 10, 2);

Comments