Skip to content

Instantly share code, notes, and snippets.

@xlplugins
Last active September 17, 2024 13:22
Show Gist options
  • Save xlplugins/dff0af185e018bf280a3c8dec68adb36 to your computer and use it in GitHub Desktop.
Save xlplugins/dff0af185e018bf280a3c8dec68adb36 to your computer and use it in GitHub Desktop.
Funnelkit: Compatibility with FastCredit for WooCommerce (Premium)
class FKCART_FastCredit_For_WC {
private $subtotal_price = null;
private $text_find = 'Credit';
public function __construct() {
add_filter( 'fkcart_enable_item_link', [ $this, 'add_item_meta' ] );
add_action( 'wfacp_after_template_found', [ $this, 'actions' ] );
}
public function actions() {
if ( ! $this->is_enable() ) {
return;
}
add_filter( 'woocommerce_cart_item_price', array( $this, 'fwc_cart_item_price' ), 99999, 3 );
add_filter( 'woocommerce_cart_item_subtotal', array( $this, 'fwc_cart_item_subtotal' ), 99999, 3 );
add_filter( 'wc_price', [ $this, 'custom_modify_wc_price' ], 9999, 4 );
}
public function add_item_meta( $status ) {
if ( ! $this->is_enable() ) {
return $status;
}
$this->actions();
return $status;
}
public function custom_modify_wc_price( $return, $price, $args, $unformatted_price ) {
if(function_exists('fwc_woocommerce_order_amount_total')){
return fwc_woocommerce_order_amount_total($return );
}
return $return;
}
public function fwc_cart_item_price( $price, $cart_item, $cart_item_key ) {
$price = fwc_cart_item_price( $price, $cart_item, $cart_item_key );
if ( ! empty( $price ) && strpos( $price, $this->text_find ) !== false ) {
$this->subtotal_price = $price;
return $price;
}
return $price;
}
public function fwc_cart_item_subtotal( $price, $cart_item, $cart_item_key ) {
$price = fwc_cart_item_subtotal( $price, $cart_item, $cart_item_key );
return $price;
}
public function is_enable() {
return function_exists( 'fwc_cart_item_price' );
}
}
new FKCART_FastCredit_For_WC();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment