Created
September 13, 2024 11:13
-
-
Save xlplugins/14511bc159759bf1f20646044dda77b2 to your computer and use it in GitHub Desktop.
Landing page Variable product to Dedicated checkout page
This file contains 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
// Note - Do not add any product here https://i.imgur.com/mcVGiNP.png | |
class WFFN_Change_Action_Of_Add_To_Cart { | |
public $checkout_url = 'http://funnellocal1.local/checkouts/checkout-copy-4/'; // redirect to this link | |
public function __construct() { | |
add_action( 'wfacp_after_checkout_page_found', [ $this, 'remove_notice' ] ); | |
add_filter( 'woocommerce_add_to_cart_form_action', [ $this, 'change_form_action' ] ); | |
} | |
public function change_form_action( $action ) { | |
global $post; | |
if ( 'wffn_landing' === $post->post_type ) { | |
$action = $this->checkout_url; | |
} | |
return $action; | |
} | |
public function remove_notice() { | |
$notices = WC()->session->get( 'wc_notices', array() ); | |
if ( ! isset( $notices['error'] ) ) { | |
return; | |
} | |
foreach ( $notices['error'] as $index => $notice ) { | |
if ( 'No product in this checkout page' === $notice['notice'] ) { | |
unset( $notices['error'][ $index ] ); | |
break; | |
} | |
} | |
WC()->session->set( 'wc_notices', $notices ); | |
} | |
} | |
new WFFN_Change_Action_Of_Add_To_Cart(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment