第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

基于產(chǎn)品 ID 在 WooCommerce 感謝頁面上添加自定義消息

基于產(chǎn)品 ID 在 WooCommerce 感謝頁面上添加自定義消息

PHP
手掌心 2022-12-03 10:26:58
我使用插件“代碼片段”在 wordpress 中放入以下代碼。我用以下代碼更改了字幕:add_filter('woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 10, 2 );function woo_change_order_received_text( $str, $order ) {    $new_str = 'Deine Bestellung ist bei uns eingegangen und wird umgehend von uns bearbeitet.';    return $new_str;}它工作得很好,但我想在客戶購買特定產(chǎn)品時添加不同的文本。我發(fā)現(xiàn)了以下代碼:<?php $present = false; ?><?php foreach( $order->get_items() as $item ):      $_product = wc_get_product( $item['product_id'] );         // Add whatever product id you want below here        if ( $item['product_id'] == 643 ):                  $present = true; ?><?php endif; endforeach; ?><?php if( $present ): ?>    <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you for buying this shirt', 'woocommerce' ), $order ); ?></p><?php else: ?>    <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p><?php endif; ?>但是當我將它添加到主題的 functions.php 或插件“代碼片段”時,它失敗了。
查看完整描述

1 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

您可以使用以下內(nèi)容,在此答案中產(chǎn)品 id = 30


function filter_woocommerce_thankyou_order_received_text( $str, $order ) {

    // Get items

    $items = $order->get_items();

 

    foreach ( $items as $item ) {

        // Compare

        if ( $item->get_product_id() == 30 ) {

            $str = __( 'Deine Bestellung ist bei uns eingegangen und wird umgehend von uns bearbeitet.', 'woocommerce' );

            break;

        }

    }

    

    return $str;

}

add_filter( 'woocommerce_thankyou_order_received_text', 'filter_woocommerce_thankyou_order_received_text', 10, 2 );


查看完整回答
反對 回復(fù) 2022-12-03
  • 1 回答
  • 0 關(guān)注
  • 117 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號