Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This code snippet is an example of how to implemnt a callback for the
- * conversion of custom products of type "booking". Please note that this is just
- * a skeleton, and no conversion is actually performed. The purpose of this code
- * is to illustrate how to interact with the Currency Switcher to add custom
- * conversion logic for custom product types.
- *
- * HOW TO USE THIS CODE
- * Simply add the code to the bottom of your theme's functions.php file, and it
- * will run automatically. For more information: https://www.skyverge.com/blog/add-custom-code-to-wordpress/
- *
- * GPL DISCLAIMER
- * Because this code program is free of charge, there is no warranty for it, to the extent permitted by applicable law.
- * Except when otherwise stated in writing the copyright holders and/or other parties provide the program "as is"
- * without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of
- * merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program
- * is with you. should the program prove defective, you assume the cost of all necessary servicing, repair or correction.
- *
- * Need a consultation, or assistance to customise this code? Find us on Codeable: https://aelia.co/hire_us
- */
- /**
- * Intercepts the product conversion callbacks used by the Currency Switcher, adding
- * new ones to handle custom products.
- *
- * @param callable $callback The original callback passed to the hook.
- * @param WC_Product The product to examine.
- * @return callable
- */
- function my_custom_conversion_callback($callback, $product) {
- if($product->is_type('booking')) {
- $callback = 'my_custom_booking_conversion';
- }
- return $callback;
- }
- add_filter('wc_aelia_currencyswitcher_product_convert_callback', array($this, 'my_custom_conversion_callback'), 10, 2);
- /**
- * Converts the prices of a booking product to the specified currency.
- *
- * @param WC_Product_MyCustomProduct product A custom product.
- * @param string currency A currency code.
- * @return WC_Product_MyCustomProduct The product with converted prices.
- */
- function my_custom_booking_conversion($product, $currency) {
- /* Here you can perform any currency related operation you need. For example,
- * if your product prices were loaded in base currency, this is the perfect
- * place to replace them with the ones in the correct currency.
- *
- * If you designed your product class with built-in multi-currency support,
- * and it automatically loads its prices in the appropriate currency, you
- * won't have to do anything here. You will still need this callback, though,
- * so that the Currency Switcher will know that someone "took care" of the
- * custom product types, and no warnings will be raised.
- */
- // Ticket 6057 - Return booking products as they are
- return $product;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement