在账单地址后的 Woocommerce 订单接收页面中添加文本
Add a text in Woocommerce order received page after the billing address
我想知道如何在 woocommerce 订单接收页面底部的账单地址后添加文本?
有没有我可以使用的钩子?
或者有什么其他方法可以做到这一点?
在 woocommerce_thankyou
操作挂钩中尝试这个自定义挂钩函数:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
经过测试并有效……
您可以在您的(子)主题或插件中添加动作挂钩。扩展@LoicTheAztec 的回答:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
这里是more actions that you can use, that are unfortunately not (yet?) mentioned in the official WooCommerce Action and Filter Hook Reference documentation:
woocommerce_before_thankyou
woocommerce_thankyou_{payment_method}
(动态)
woocommerce_thankyou
有时您需要订单详细信息和送货方式。要获取订单详细信息,您可以使用 $order = new WC_Order($order_id);
。例如:
function produkindo_before_thankyou($order_id) {
$order = new WC_Order($order_id);
// Iterating through order shipping items
foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ){
// $order_item_name = $shipping_item_obj->get_name();
// $order_item_type = $shipping_item_obj->get_type();
// "Prahu-Hub" or "Prahu - Hub"
$shipping_method_title = $shipping_item_obj->get_method_title();
$shipping_method_id = $shipping_item_obj->get_method_id(); // The method ID
$shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID
// $shipping_method_total = $shipping_item_obj->get_total();
// $shipping_method_total_tax = $shipping_item_obj->get_total_tax();
// $shipping_method_taxes = $shipping_item_obj->get_taxes();
break;
}
if (preg_match('/^Prahu/i', $shipping_method_title)) {
?>
<div class="prahu-hub-thankyou">
Silakan melanjutkan pemesanan pengiriman untuk barang yang Anda beli di <a target="_blank" href="https://prahu-hub.com/home/pencarian"><strong>Prahu–Hub</strong></a>.
</div>
<?php
}
}
add_action('woocommerce_before_thankyou', 'produkindo_before_thankyou');
我想知道如何在 woocommerce 订单接收页面底部的账单地址后添加文本?
有没有我可以使用的钩子?
或者有什么其他方法可以做到这一点?
在 woocommerce_thankyou
操作挂钩中尝试这个自定义挂钩函数:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
经过测试并有效……
您可以在您的(子)主题或插件中添加动作挂钩。扩展@LoicTheAztec 的回答:
add_action( 'woocommerce_thankyou', 'custom_content_thankyou', 10, 1 );
function custom_content_thankyou( $order_id ) {
echo '<p>'. __('My custom text').'</p>';
}
这里是more actions that you can use, that are unfortunately not (yet?) mentioned in the official WooCommerce Action and Filter Hook Reference documentation:
woocommerce_before_thankyou
woocommerce_thankyou_{payment_method}
(动态)woocommerce_thankyou
有时您需要订单详细信息和送货方式。要获取订单详细信息,您可以使用 $order = new WC_Order($order_id);
。例如:
function produkindo_before_thankyou($order_id) {
$order = new WC_Order($order_id);
// Iterating through order shipping items
foreach( $order->get_items( 'shipping' ) as $item_id => $shipping_item_obj ){
// $order_item_name = $shipping_item_obj->get_name();
// $order_item_type = $shipping_item_obj->get_type();
// "Prahu-Hub" or "Prahu - Hub"
$shipping_method_title = $shipping_item_obj->get_method_title();
$shipping_method_id = $shipping_item_obj->get_method_id(); // The method ID
$shipping_method_instance_id = $shipping_item_obj->get_instance_id(); // The instance ID
// $shipping_method_total = $shipping_item_obj->get_total();
// $shipping_method_total_tax = $shipping_item_obj->get_total_tax();
// $shipping_method_taxes = $shipping_item_obj->get_taxes();
break;
}
if (preg_match('/^Prahu/i', $shipping_method_title)) {
?>
<div class="prahu-hub-thankyou">
Silakan melanjutkan pemesanan pengiriman untuk barang yang Anda beli di <a target="_blank" href="https://prahu-hub.com/home/pencarian"><strong>Prahu–Hub</strong></a>.
</div>
<?php
}
}
add_action('woocommerce_before_thankyou', 'produkindo_before_thankyou');