Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save xlplugins/4eca00f0298631e61f1a2ab524a865c1 to your computer and use it in GitHub Desktop.
Save xlplugins/4eca00f0298631e61f1a2ab524a865c1 to your computer and use it in GitHub Desktop.
Checkout : Move the position of rewards point into the mini cart plugin by WooCommerce Points and Rewards By WooCommerce
class WFACP_Compatibility_With_WC_Points_and_Reward_mini_cart {
public $instance = null;
public $message = '';
public $count = 0;
public function __construct() {
/* Unhook rewards and points */
add_action( 'wfacp_template_load', [ $this, 'actions' ], 9 );
add_action( 'wfacp_mini_cart_before_order_total', [ $this, 'render_message' ] );
add_filter( 'woocommerce_update_order_review_fragments', [ $this, 'add_fragments' ], 150 );
add_action( 'wfacp_after_checkout_page_found', array( $this, 'maybe_setup_page' ), 7 );
add_action( 'wfacp_internal_css', [ $this, 'internal_css' ] );
}
public function maybe_setup_page() {
WFACP_Common::remove_actions( 'wfacp_template_load', 'WFACP_Compatibility_With_WC_Points_and_Reward', 'actions' );
WFACP_Common::remove_actions( 'wfacp_before_form', 'WFACP_Compatibility_With_WC_Points_and_Reward', 'render_message' );
WFACP_Common::remove_actions( 'woocommerce_update_order_review_fragments', 'WFACP_Compatibility_With_WC_Points_and_Reward', 'add_fragments' );
$instance = WFACP_Common::remove_actions( 'woocommerce_before_checkout_form', 'WC_Points_Rewards_Cart_Checkout', 'render_redeem_points_message' );
add_action( 'wfacp_mini_cart_before_order_total', array( $instance, 'render_redeem_points_message' ), 999 );
}
public function actions() {
if ( is_admin() ) {
return;
}
if ( is_null( WC()->cart ) ) {
return;
}
WFACP_Common::remove_actions( 'woocommerce_applied_coupon', 'WC_Points_Rewards_Cart_Checkout', 'discount_updated' );
$this->instance = WFACP_Common::remove_actions( 'woocommerce_before_checkout_form', 'WC_Points_Rewards_Cart_Checkout', 'render_earn_points_message' );
if ( ! $this->instance instanceof WC_Points_Rewards_Cart_Checkout ) {
return;
}
ob_start();
$this->instance->render_earn_points_message();
$this->message = ob_get_clean();
}
public function add_fragments( $fragments ) {
if ( ! $this->instance instanceof WC_Points_Rewards_Cart_Checkout || empty( $this->message ) ) {
return $fragments;
}
$fragments['.wc_points_rewards_earn_points'] = $this->message;
return $fragments;
}
public function render_message() {
if ( empty( $this->message ) ) {
return;
}
echo '<div class=wfacp_wc_rewards_checkout>';
echo $this->message;
echo "</div>";
}
public function internal_css() {
?>
<style>
.wfacp_woocommerce_form_coupon.wfacp_template_9_coupon + .wfacp_wc_rewards_checkout {
display: none !important;
}
</style>
<?php
}
}
new WFACP_Compatibility_With_WC_Points_and_Reward_mini_cart();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment