簡體   English   中英

WooCommerce - 通過送貨方式在感謝頁面上添加內容

[英]WooCommerce - Add content on the thank you page by the shipping method

完成訂單后,我想在 WooCommerce 的感謝頁面上放置我自己的內容(在我的情況下是短代碼),這取決於運輸方式。

例如:配送方式 1:內容 1 配送方式 2:內容 2 配送方式 3:無內容

我已經在這里找到了一些文本內容,但我沒有插入短代碼。 或者,我在這里測試了與短代碼一起使用的內容,其中缺少對運輸方式的依賴。

也許有人可以幫助我實現這一點。 理想情況下,內容應位於帶有訂單信息的表格上方。

非常感謝!

可能是您將shortcode添加到thank you文本的方式可能是問題所在。

請參閱以下我為演示創建的稱為avengers 的shortcode函數。

function call_avangers( $atts ){
    return "<p>Avengers . . . .  Assemble !!!</p>";
}
add_shortcode( 'avengers', 'call_avangers' );

您可以使用以下功能在感謝頁面中顯示此短代碼

add_filter( 'woocommerce_thankyou_order_received_text', 'woo_change_order_received_text', 20, 2 );
function woo_change_order_received_text( $text, $order ) {
    if( $order->get_shipping_method() == 'your_shipping_method_here' ) {
        $text .= do_shortcode('[avengers]');
    }
    return $text;
}

基本的事情是你必須調用do_shortcode('your_shortcode_name')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM