亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

WooCommerce 在訂單通知中顯示高級自定義字段 (ACF)

WooCommerce 在訂單通知中顯示高級自定義字段 (ACF)

PHP
忽然笑 2023-05-12 15:52:14
我添加了以下代碼片段以顯示自定義字段(如果產品有字段,則不顯示分類字段)和預計交貨時間。這是工作。    <?php add_action( 'woocommerce_before_add_to_cart_form', 'geschatte_levertijd', 10 );        function geschatte_levertijd (){    if( get_field('plevertijd') ): ?>            <span class="product_melding_kleur"><i class="fa fa-truck"></i>Levertijd: <a href="/verzending-en-levertijd/" alt="Verzending en levertijd" ><?php the_field( 'plevertijd' ); ?></a></span>        <?php else: ?>    <? $terms = get_the_terms( $post->ID, 'product_cat' );            if ( !empty($terms)):            $term = array_pop($terms);                    $text= get_field('levertijd', $term);                    if (!empty($levertijd))?>                <span class="product_melding_kleur"><i class="fa fa-truck"></i>Levertijd: <a href="/verzending-en-levertijd/" alt="Verzending en levertijd" ><?php the_field( 'levertijd', $term ); ?></a></span>    <?php endif; ?>    <?php endif;         }    ?>但現在我正試圖在訂單通知郵件中顯示該字段。在產品標題下方。有人可以指出我如何做到這一點的正確方向嗎?
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

以下將使用您的代碼實現訂單商品名稱下的訂單電子郵件通知顯示:


add_action( 'woocommerce_order_item_meta_start', 'add_estimated_delivery_time_to_emails', 10, 3 );

function add_estimated_delivery_time_to_emails( $item_id, $item, $order ) {

    // On email notifications and for line items

    if ( ! is_wc_endpoint_url() && $item->is_type('line_item') ) { 

        if( $plevertijd = get_field('plevertijd', $item->get_product_id() ) ) {

            echo '<span class="product_melding_kleur"><i class="fa fa-truck"></i>Levertijd: <a href="/verzending-en-levertijd/" alt="Verzending en levertijd" >' . $plevertijd . '</a></span>';

        } else {

            $terms = get_the_terms( $item->get_product_id(), 'product_cat' );

            

            if ( ! empty($terms) ) {

                $term = array_pop( $terms );

                

                if( $levertijd = get_field('levertijd', $term ) ) {

                    echo '<span class="product_melding_kleur"><i class="fa fa-truck"></i>Levertijd: <a href="/verzending-en-levertijd/" alt="Verzending en levertijd" >' . $levertijd . '</a></span>';

                }

            }

        } 

    }

}

代碼進入您的活動子主題(或活動主題)的 functions.php 文件。它應該有效。


在前端訂單上顯示:


如果您希望它顯示在客戶訂單(前端)上,您可以從IF聲明中刪除以下內容:! is_wc_endpoint_url() &&


您也可以改用woocommerce_order_item_meta_end掛鉤,以在產品變體的產品屬性之后顯示。


查看完整回答
反對 回復 2023-05-12
  • 1 回答
  • 0 關注
  • 196 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號