我使用插件“代码片段”在 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;
}
它工作得很好,但我想在客户购买特定产品时添加不同的文本。
我发现了以下代码:
<?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 或插件“代码片段”时,它失败了。
神不在的星期二