📜  通过 shortcide 添加 cuponcode 代码形式 - 任何代码示例

📅  最后修改于: 2022-03-11 15:00:17.843000             🧑  作者: Mango

代码示例1
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  = '

'; $output .= isset($coupon) ? '

'.$message.'

' : ''; return $output . '
'; }