📅  最后修改于: 2022-03-11 15:00:17.843000             🧑  作者: Mango
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 = '';
}