php WOO货币切换器的压轴折扣兼容性

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WOO货币切换器的压轴折扣兼容性相关的知识,希望对你有一定的参考价值。

<?php
/**
* Compatibility for WooCommerce Currency Switcher 
*/

if(class_exists('WCCT_Core')){
class WCCT_Discounts_Compatibility_For_WOOCS {
	public static $_instance = null;

	public function __construct() {

		add_action( 'wcct_before_get_regular_price', array( $this, 'maybe_unhook_regular_price_filters' ) );

		add_action( 'wcct_after_get_regular_price', array( $this, 'maybe_rehook_regular_price_filters' ) );
		if ( isset( $GLOBALS['WOOCS'] ) && $GLOBALS['WOOCS'] instanceof WOOCS ) {

			remove_filter( 'woocommerce_get_variation_prices_hash', array( $GLOBALS['WOOCS'], 'woocommerce_get_variation_prices_hash' ), 9999, 3 );

		}


	}

	public static function get_instance() {
		if ( null == self::$_instance ) {
			self::$_instance = new self;
		}

		return self::$_instance;
	}

	public function maybe_unhook_regular_price_filters() {

		if ( isset( $GLOBALS['WOOCS'] ) && $GLOBALS['WOOCS'] instanceof WOOCS && $GLOBALS['WOOCS']->is_multiple_allowed == '1' ) {

			remove_filter( 'woocommerce_product_get_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			//wp-content\plugins\woocommerce\includes\abstracts\abstract-wc-data.php
			//protected function get_prop
			remove_filter( 'woocommerce_product_variation_get_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			remove_filter( 'woocommerce_product_variation_get_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );

			//comment next code line if on single product page for variable prices you see crossed out price which equal to the regular one,
			//I mean you see 2 same prices (amounts) and one of them is crossed out which by logic should not be visible at all
			//remove_filter('woocommerce_product_variation_get_sale_price', array($this, 'raw_woocommerce_price'), 9999, 2);
			//new  function  for sale price
			remove_filter( 'woocommerce_product_variation_get_sale_price', array( $GLOBALS['WOOCS'], 'raw_sale_price_filter' ), 9999, 2 );
			remove_filter( 'woocommerce_product_get_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			remove_filter( 'woocommerce_product_get_sale_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price_sale' ), 9999, 2 );


			remove_filter( 'woocommerce_get_variation_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 4 );
			remove_filter( 'woocommerce_get_variation_sale_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 4 );
			remove_filter( 'woocommerce_variation_prices', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );

			remove_filter( 'woocommerce_variation_prices_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			remove_filter( 'woocommerce_variation_prices_regular_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			remove_filter( 'woocommerce_variation_prices_sale_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			remove_filter( 'woocommerce_get_variation_prices_hash', array( $GLOBALS['WOOCS'], 'woocommerce_get_variation_prices_hash' ), 9999, 3 );

		}
	}

	public function maybe_rehook_regular_price_filters() {

		if ( isset( $GLOBALS['WOOCS'] ) && $GLOBALS['WOOCS'] instanceof WOOCS && $GLOBALS['WOOCS']->is_multiple_allowed == '1' ) {
			add_filter( 'woocommerce_product_get_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			//wp-content\plugins\woocommerce\includes\abstracts\abstract-wc-data.php
			//protected function get_prop
			add_filter( 'woocommerce_product_variation_get_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			add_filter( 'woocommerce_product_variation_get_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );

			//comment next code line if on single product page for variable prices you see crossed out price which equal to the regular one,
			//I mean you see 2 same prices (amounts) and one of them is crossed out which by logic should not be visible at all
			//remove_filter('woocommerce_product_variation_get_sale_price', array($this, 'raw_woocommerce_price'), 9999, 2);
			//new  function  for sale price
			add_filter( 'woocommerce_product_variation_get_sale_price', array( $GLOBALS['WOOCS'], 'raw_sale_price_filter' ), 9999, 2 );
			add_filter( 'woocommerce_product_get_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 2 );
			//	add_filter( 'woocommerce_product_get_sale_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price_sale' ), 9999, 2 );


			add_filter( 'woocommerce_get_variation_regular_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 4 );
			add_filter( 'woocommerce_get_variation_sale_price', array( $GLOBALS['WOOCS'], 'raw_woocommerce_price' ), 9999, 4 );
			add_filter( 'woocommerce_variation_prices', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );

			add_filter( 'woocommerce_variation_prices_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			add_filter( 'woocommerce_variation_prices_regular_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			add_filter( 'woocommerce_variation_prices_sale_price', array( $GLOBALS['WOOCS'], 'woocommerce_variation_prices' ), 9999, 3 );
			//	add_filter( 'woocommerce_get_variation_prices_hash', array( $GLOBALS['WOOCS'], 'woocommerce_get_variation_prices_hash' ), 9999, 3 );

		}
	}

}
WCCT_Discounts_Compatibility_For_WOOCS::get_instance();
}

以上是关于php WOO货币切换器的压轴折扣兼容性的主要内容,如果未能解决你的问题,请参考以下文章

php 货币切换器

PHP PHP货币转换器(谷歌版)

php 与Algoritmika有限公司的WooCommerce货币交换机的兼容性

php 重力Wiz //重力形式//货币转换器

php [WooCommerce货币转换器小部件]使用国家标志而不是国家代码。

php Woo Checkout Fields&Arrays #woo