symbol sulssymbol sulssymbol suls

הצגת קודי קופונים בהתראות אימייל של ווקומרס

קטע קוד זה בודק את כל קודי הקופון המשתמשים בהזמנה.

אם הוא נמצא, הוא מאחזר את סוג הקופון, השם והסכום.

עבור הנחות מבוססות אחוזים, הסכום מלווה בסמל אחוז. עבור הנחות מבוססות קבועות, קידומת הסכום היא סמל המטבע.

קודי הקופון מוצגים בטבלה מעוצבת היטב עם CSS מוחל כדי להתאים לסגנון של טבלאות אחרות בדוא"ל.

גם שם ההנחה וגם הסכום מוצגים מתחת לטבלת פרטי ההזמנה הראשית.

תהנו 🙂


/**
 * Snippet Name:	WooCommerce Showing coupon codes used in email
 * Snippet Author:	suls.co.il
 */

add_action( 'woocommerce_email_after_order_table', 'suls_Showing_coupon_codes_used_in_WooCommerce_email', 15, 4 );
function suls_Showing_coupon_codes_used_in_WooCommerce_email( $order, $sent_to_admin, $plain_text, $email ) {
    if (count( $order->get_coupons() ) > 0 ) {
        $html = '<div class="used-coupons">
        <h2>קופונים<h2>
        <table class="td" cellspacing="0" cellpadding="6" border="1"><tr>
        <th>קוד קופון</th>
        <th>הנחה</th>
        </tr>';

        foreach( $order->get_coupons() as $item ){
            $coupon_code   = $item->get_code();
            $coupon = new WC_Coupon($coupon_code);
			$discount_type = $coupon->get_discount_type();
			$coupon_amount = $coupon->get_amount();

			if ($discount_type == 'percent') {
				$output = $coupon_amount . "%";
			} else {
				$output = wc_price($coupon_amount);
			}

            $html .= '<tr>
                <td>' . strtoupper($coupon_code) . '</td>
                <td>' . $output . '</td>
            </tr>';
        }
        $html .= '</table><br></div>';

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

        echo $css . $html;
    }
}

עוד מאמרים מעניינים