купон - отобразить через шорткод и перед кнопкой "оформить заказ"
Sun Jan 16 2022 18:38:47 GMT+0000 (Coordinated Universal Time)
Saved by
@mastaklance
// Display a WooCommerce coupon input field anywhere with a shortcode [coupon_field]
add_shortcode( 'coupon_field', 'display_coupon_field' );
function display_coupon_field() {
if( isset($_GET['coupon']) && isset($_GET['redeem-coupon']) ){
if( $coupon = esc_attr($_GET['coupon']) ) {
$applied = WC()->cart->apply_coupon($coupon);
} else {
$coupon = false;
}
$success = sprintf( __('Coupon "%s" Applied successfully.'), $coupon );
$error = __("This Coupon can't be applied");
$message = isset($applied) && $applied ? $success : $error;
}
$output = '<div class="redeem-coupon"><form id="coupon-redeem">
<p><input type="text" name="coupon" id="coupon"/>
<input type="submit" name="redeem-coupon" value="'.__('Redeem Offer').'" /></p>';
$output .= isset($coupon) ? '<p class="result">'.$message.'</p>' : '';
return $output . '</form></div>';
}
// Move custom coupon shortcode before Proceed to checkout button
add_action('woocommerce_proceed_to_checkout','ml_callback_function');
function ml_callback_function(){
echo do_shortcode( '[coupon_field]' );
}
content_copyCOPY
Comments