Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将应用的优惠券说明添加到WooCommerce管理员电子邮件通知_Php_Wordpress_Woocommerce_Email Notifications_Coupon - Fatal编程技术网

Php 将应用的优惠券说明添加到WooCommerce管理员电子邮件通知

Php 将应用的优惠券说明添加到WooCommerce管理员电子邮件通知,php,wordpress,woocommerce,email-notifications,coupon,Php,Wordpress,Woocommerce,Email Notifications,Coupon,试图将申请优惠券的说明放入“新订单”管理电子邮件,但未成功 到目前为止,我一直在尝试使用我放在functions.php中的这段代码 add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 ); function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) { // Only for a

试图将申请优惠券的说明放入“新订单”管理电子邮件,但未成功

到目前为止,我一直在尝试使用我放在functions.php中的这段代码

add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {

    // Only for admins and when there at least 1 coupon in the order
    if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;

    foreach( $order->get_items('coupon') as $coupon ){
        $coupon_codes[] = $coupon->get_code();
        $coupon_desc[] = $coupon->get_description();

    }
    // For one coupon
    if( count($coupon_codes) == 1 ){
        $coupon_code = reset($coupon_codes);
        echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';

        $coupon_des = reset($coupon_desc);
        echo '<p>'.__( 'Coupon Description: ').$coupon_des.'<p>';
    } 
    // For multiple coupons
}
add_action('woocommerce_email_order_details','display_applicated_coups',10,4);
功能显示应用的优惠券($order,$sent,$admin,$plain,$email){
//仅适用于管理员,且订单中至少有一张优惠券
如果(!$sent_to_admin&&count($order->get_items('优惠券'))==0)返回;
foreach($order->get_items('优惠券')作为$优惠券){
$优惠券\代码[]=$优惠券->获取\代码();
$优惠券描述[]=$优惠券->获取描述();
}
//一张优惠券
if(计数($优惠券代码)==1){
$优惠券代码=重置($优惠券代码);
回显“”。(使用的优惠券:)。$优惠券代码。“”;
$coupon_des=重置($coupon_desc);
回显“”。(优惠券说明:)。$优惠券名称。;
} 
//多张优惠券
}
除非它不会产生任何错误,否则我无法在“新订单”管理员电子邮件中看到优惠券说明


有人能帮我吗?提前感谢您

您的代码中有一些错误…请尝试以下操作:

add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for admins and when there at least 1 coupon in the order
    if ( $sent_to_admin && count( $order->get_coupons() ) > 0 ) {
        $html = '<div class="coupon-items">
        <h2>' . __( "Used coupons" ) . '<h2>
        <table class="td" cellspacing="0" cellpadding="6" border="1"><tr>
        <th>' . __("Code") . '</th>
        <th>' . __("Description") . '</th>
        </tr>';

        foreach( $order->get_coupons() as $item ){
            $code   = $item->get_code();
            $coupon = new WC_Coupon($code);

            $html .= '<tr>
                <td>' . ucfirst( $code ) . '</td>
                <td>' . $coupon->get_description() . '</td>
            </tr>';
        }
        $html .= '</table><br></div>';

        // The CSS styling
        $css = '<style>
            .coupon-items table{width: 100%; font-family: \'Helvetica Neue\', Helvetica, Roboto, Arial, sans-serif;
                color: #737373; border: 1px solid #e4e4e4; margin-bottom:8px;}
            .coupon-items table th, table.tracking-info td{text-align: left; border-top-width: 4px;
                color: #737373; border: 1px solid #e4e4e4; padding: 12px;}
            .coupon-items table td{text-align: left; border-top-width: 4px; color: #737373; border: 1px solid #e4e4e4; padding: 12px;}
        </style>';

        // The Output CSS + HTML
        echo $css . $html;
    }
}
add_action('woocommerce_email_order_details','display_applicated_coups',10,4);
功能显示应用的优惠券($order,$sent,$admin,$plain,$email){
//仅适用于管理员,且订单中至少有一张优惠券
如果($sent_to_admin&&count($order->get_coups())>0){
$html='1
“.”(“二手券”)。”
“.”(“代码”)。”
“说明”
';
foreach($order->get_coups()作为$item){
$code=$item->get_code();
$coupon=新WC_优惠券($code);
$html.='
“.ucfirst($code)。”
“.$优惠券->获取描述()
';
}
$html.='
'; //CSS样式 $css='1 .优惠券项目表{宽度:100%;字体系列:\'Helvetica Neue\',Helvetica,Roboto,Arial,无衬线; 颜色:#737373;边框:1px实心#e4;边距底部:8px;} .优惠券项目表th,表.tracking-info td{文本对齐:左侧;边框顶部宽度:4px; 颜色:#737373;边框:1px实心#e4;填充:12px;} .优惠券项目表td{文本对齐:左;边框顶部宽度:4px;颜色:#737373;边框:1px实心#e4;填充:12px;} '; //输出CSS+HTML echo$css.$html; } }
代码进入活动子主题(或活动主题)的functions.php文件。测试和工作


功能齐全。非常感谢。