Created
December 4, 2025 10:53
-
-
Save xlplugins/a72edb7288e3c2658eb6b806a50513e9 to your computer and use it in GitHub Desktop.
Funnelkit Cart: Displays minimum purchase error in FunnelKit slide cart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ( ! class_exists( 'CT_MPAC_FKCart_Compat' ) ) { | |
| class CT_MPAC_FKCart_Compat { | |
| public function __construct() { | |
| add_action( 'plugins_loaded', array( $this, 'init' ) ); | |
| } | |
| public function init() { | |
| // Check if both plugins are active | |
| if ( ! class_exists( 'CtMPAC_Application' ) || ! class_exists( 'FKCart\Includes\Front' ) ) { | |
| return; | |
| } | |
| add_action( 'fkcart_before_body', array( $this, 'show_notice' ) ); | |
| add_filter( 'fkcart_cart_link', array( $this, 'disable_checkout' ), 10, 2 ); | |
| add_action( 'wp_head', array( $this, 'add_styles' ) ); | |
| } | |
| public function show_notice() { | |
| if ( is_null( WC()->cart ) || WC()->cart->is_empty() ) return; | |
| // Use existing plugin methods via static call | |
| $min = get_option( 'ct_mpac_minimum_purchase_value_for_all', 0 ); | |
| $min = apply_filters( 'ct_mpac_filter_min_cart_total', $min, WC()->cart ); | |
| $current = WC()->cart->total; | |
| $current = apply_filters( 'ct_mpac_filter_current_cart_total', $current, WC()->cart ); | |
| if ( $current > 0 && $current < $min ) { | |
| // Use the existing plugin's getErrorNotice method | |
| $message = CtMPAC_Application::getErrorNotice( $min, $current ); | |
| if ( $message ) { | |
| echo '<div class="fkcart-mpac-wrap woocommerce-error" role="alert">' . wp_kses_post( $message ) . '</div>'; | |
| } | |
| } | |
| } | |
| public function disable_checkout( $link, $front ) { | |
| if ( ! get_option( 'ct_mpac_cart_disable_checkout', false ) ) return $link; | |
| if ( is_null( WC()->cart ) || WC()->cart->is_empty() ) return $link; | |
| $min = apply_filters( 'ct_mpac_filter_min_cart_total', get_option( 'ct_mpac_minimum_purchase_value_for_all', 0 ), WC()->cart ); | |
| $current = apply_filters( 'ct_mpac_filter_current_cart_total', WC()->cart->total, WC()->cart ); | |
| return ( $current !== 0 && $current < $min ) ? '#' : $link; | |
| } | |
| public function add_styles() { | |
| ?> | |
| <style> | |
| .fkcart-mpac-wrap { margin: 0 16px 12px; padding: 12px 16px; border-radius: 6px; font-size: 14px; } | |
| .fkcart-mpac-wrap .ct-mpac-minimum-amount, | |
| .fkcart-mpac-wrap .ct-mpac-current-amount, | |
| .fkcart-mpac-wrap .ct-mpac-remaining-amount { font-weight: 600; } | |
| </style> | |
| <?php | |
| } | |
| } | |
| new CT_MPAC_FKCart_Compat(); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment