Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modal checkout redesign tweaks #2805

Merged
merged 9 commits into from
Dec 20, 2023
43 changes: 32 additions & 11 deletions includes/class-donations.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ class Donations {
*/
public static function init() {
self::$donation_product_name = __( 'Donate', 'newspack' );
if ( ! is_admin() ) {
add_action( 'wp_loaded', [ __CLASS__, 'process_donation_form' ], 99 );
add_action( 'woocommerce_checkout_update_order_meta', [ __CLASS__, 'woocommerce_checkout_update_order_meta' ] );
add_filter( 'woocommerce_billing_fields', [ __CLASS__, 'woocommerce_billing_fields' ] );
add_filter( 'pre_option_woocommerce_enable_guest_checkout', [ __CLASS__, 'disable_guest_checkout' ] );
add_action( 'woocommerce_check_cart_items', [ __CLASS__, 'handle_cart' ] );
add_filter( 'amp_skip_post', [ __CLASS__, 'should_skip_amp' ], 10, 2 );
add_filter( 'newspack_blocks_donate_billing_fields_keys', [ __CLASS__, 'get_billing_fields' ] );
add_action( 'woocommerce_checkout_create_order_line_item', [ __CLASS__, 'checkout_create_order_line_item' ], 10, 4 );
add_action( 'woocommerce_coupons_enabled', [ __CLASS__, 'disable_coupons' ] );
}

add_action( 'wp_loaded', [ __CLASS__, 'process_donation_form' ], 99 );
add_action( 'woocommerce_checkout_update_order_meta', [ __CLASS__, 'woocommerce_checkout_update_order_meta' ] );
add_filter( 'woocommerce_billing_fields', [ __CLASS__, 'woocommerce_billing_fields' ] );
add_filter( 'pre_option_woocommerce_enable_guest_checkout', [ __CLASS__, 'disable_guest_checkout' ] );
add_action( 'woocommerce_check_cart_items', [ __CLASS__, 'handle_cart' ] );
add_filter( 'amp_skip_post', [ __CLASS__, 'should_skip_amp' ], 10, 2 );
add_filter( 'newspack_blocks_donate_billing_fields_keys', [ __CLASS__, 'get_billing_fields' ] );
add_action( 'woocommerce_checkout_create_order_line_item', [ __CLASS__, 'checkout_create_order_line_item' ], 10, 4 );
add_filter( 'woocommerce_coupons_enabled', [ __CLASS__, 'disable_coupons' ] );
add_filter( 'wcs_place_subscription_order_text', [ __CLASS__, 'order_button_text' ], 9 );
add_filter( 'woocommerce_order_button_text', [ __CLASS__, 'order_button_text' ], 9 );
add_filter( 'option_woocommerce_subscriptions_order_button_text', [ __CLASS__, 'order_button_text' ], 9 );
}

/**
Expand Down Expand Up @@ -614,6 +616,10 @@ public static function is_platform_other() {
* Handle submission of the donation form.
*/
public static function process_donation_form() {
if ( is_admin() ) {
return;
}

$is_wc = self::is_platform_wc();

$donation_form_submitted = filter_input( INPUT_GET, 'newspack_donate', FILTER_SANITIZE_NUMBER_INT );
Expand Down Expand Up @@ -1046,6 +1052,9 @@ public static function update_billing_fields( $billing_fields ) {
* @return bool
*/
public static function disable_coupons( $enabled ) {
if ( is_admin() ) {
return $enabled;
}
$cart = WC()->cart;
if ( ! $cart ) {
return $enabled;
Expand All @@ -1055,5 +1064,17 @@ public static function disable_coupons( $enabled ) {
}
return false;
}

/**
* Set the "Place order" button text.
*
* @param string $text The button text.
*/
public static function order_button_text( $text ) {
if ( self::is_donation_cart() ) {
return __( 'Donate now', 'newspack-plugin' );
}
return $text;
}
}
Donations::init();
4 changes: 4 additions & 0 deletions includes/class-recaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ public static function verify_recaptcha_on_checkout() {
if ( ! $should_verify_captcha ) {
return;
}
// Bail if validating form.
if ( isset( $_POST['woocommerce_checkout_update_totals'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
return;
}
$token = isset( $_POST['g-recaptcha-response'] ) ? sanitize_text_field( wp_unslash( $_POST['g-recaptcha-response'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$check = self::verify_captcha( $token );
if ( \is_wp_error( $check ) ) {
Expand Down