【发布时间】:2017-12-13 20:08:35
【问题描述】:
我想让 woocommerce 在使用 Ship to different address 且客户之前未成功订购时更改订单的订单状态。 Woocommerce 需要区分过去失败的订单,因为客户可能以前尝试过但失败了,这意味着他们将在系统中有订单,但会失败、取消或待处理。
我已经在系统中创建了一个名为 “验证” 的新订单状态,我现在想在下订单时运行一个脚本,其中包含“运送到不同地址”选项,该选项将检查客户之前是否下过订单。如果不是,则将订单状态更改为“验证”。
我尝试的第一件事是使用以下代码向客户发出警报,如果他们只有一个订单显示您的订单在验证之前不会发货。但无论您有多少订单,它都会显示。
我尝试在functions.php 文件中设置此代码:
function wc_get_customer_orders() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => 1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$customer = wp_get_current_user();
// Text for our message
$notice_text = sprintf( 'Hey %1$s 😀 As this is your first order with us, we will need to verify some info before shipping.', $customer->display_name );
// Display our notice if the customer has no orders
if ( count( $customer_orders ) == 1 ) {
wc_print_notice( $notice_text, 'notice' );
}
}
add_action( 'woocommerce_before_my_account', 'wc_get_customer_orders' );
我缺少的是一种仅在他们选择运送到不同地址及其第一笔订单时才触发此警报的方法。
还需要在此处触发更新状态以进行验证的代码。
任何帮助将不胜感激。
【问题讨论】:
标签: php wordpress woocommerce checkout account