您好,我使用的是 Woocommerce 版本 3.2.6。我们有一些订单。
我想在 wordpress 后端的订单编辑页面中product id为订单添加一项额外的详细信息。123
我想添加这个:
<a href="http://example.com/new-view/?id=<?php echo $order_id?;>">Click here to view this</a>
Run Code Online (Sandbox Code Playgroud)
即:我们有order[order id =3723],订购的商品 id 是123。
然后在 中http://example.com/wp-admin/post.php?post=3723&action=edit,我想在相应的项目详细信息下方添加以下链接:
"<a href="http://example.com/new-view/?id=<?php echo $order_id?;>">Click here to view this</a>"
Run Code Online (Sandbox Code Playgroud)
我们怎样才能做到这一点?
哪个钩子适合这个。实际上我正在搜索https://docs.woocommerce.com/wc-apidocs/hook-docs.html。
我找到了 Class WC_Meta_Box_Order_Items。但我不知道如何使用这个。
在WooCommerce 3.0出现之前,我的代码就像一种魅力,可以将购物车中的自定义值保存到结账时的订单中。但从那以后,我无法为订单创建自定义元数据。
环境: Wordpress 4.9.4 & WooCommerce 3.3.3
add_action('woocommerce_checkout_update_order_meta', 'custom_meta_to_order', 20, 1);add_action('woocommerce_checkout_create_order', 'custom_meta_to_order', 20, 1);第 1 个钩子是我尝试最多的一个,第 2 个钩子只是本主题中提到的一些字面变化的实验。
以下函数代码与钩子编号 1 相关:
if (!function_exists('custom_meta_to_order')) {
function custom_meta_to_order($order_id, $values) {
$order = wc_get_order( $order_id );
$order->update_meta_data('_TESTKEYstart', 'Hello');
if (isset($values['myValue'])) {
$myValue = $values['myValue'];
if (!empty($myValue)) $order->update_meta_data('_myKey', $myValue);
}
$order->update_meta_data('_TESTKEYend', 'Bye');
$order->save();
}
}
Run Code Online (Sandbox Code Playgroud)
我还检查了 mySQL 表中table wp_woocommerce_order_itemmeta是否至少会创建两个_TESTKEY* -meta - entrys(因为它们没有条件)。
我们需要传递以下 WooCommerce 参数,但我们不能并且出现错误。
主要问题是获取所有产品数量、购买的每种产品的数量、产品 SKU
这是我们的代码:
add_action( 'woocommerce_thankyou', 'the_tracking' );
function the_tracking( $order_id ) {
global $woocommerce;
$order = wc_get_order( $order_id );
$total = $order->get_total();
$currency = get_woocommerce_currency();
$subtotal = $woocommerce->cart->subtotal;
$coupons = $order->get_used_coupons();
$coupon_code = '';
$discount = $order->get_total_discount();
foreach ($coupons as $coupon){
$coupon_code = $coupon;
}
$tracking = 'OrderID='.$order.'&ITEMx=[ItemSku]&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT='. $total .'&DISCOUNT='. $discount .'&CURRENCY='. $currency .'&COUPON='. $coupon_code .'';
echo $tracking;
}
Run Code Online (Sandbox Code Playgroud)
但它并没有给我们带来我们应该需要的预期结果。
任何帮助表示赞赏。
我正在尝试为emails/email-header.phpWoocommerce 模板文件中的某些条件内容获取 WooCommerce 电子邮件标头中的订单项
我曾尝试print_r了$order,但它是空的,而不是让任何结果。
任何帮助表示赞赏。
我想获取 WooCommerce 中的处理订单计数。我在代码片段插件中使用以下代码,但它有效。
if( !function_exists( 'wc_processing_order_count' ) ) {
require_once '../plugins/woocommerce/includes/wc-order-functions.php';
}
// NOTICE! Understand what this does before running.
$result = wc_processing_order_count();
Run Code Online (Sandbox Code Playgroud)
它什么也没返回。
对于 Woocommerce,我在下面编写了代码,尝试获取今天的订单总购买量:
function order_total_woo_fahad(){
// Get orders from people named John that were paid in the year 2016.
$orders = wc_get_orders( array(
'date_paid' => '2018-07-03'
) );
$total_of_all=0;
for($i=0;$orders[i];$i++)
$total_of_all= $orders[i]->get_total();
return $total_of_all;
}
Run Code Online (Sandbox Code Playgroud)
但它返回空值。
我做错了什么?如何获取当天的订单总购买金额?
所以我有一个变量,如果我使用var_dump该变量,我会得到一个大数组。我正在尝试获得以下内容:
["name"]=> string(26) "Online marketing Duitsland"
Run Code Online (Sandbox Code Playgroud)
整个数组结果如下所示:
array(1) {
[33]=> object(WC_Order_Item_Product)#9730 (11) {
["extra_data":protected]=> array(9) {
["product_id"]=> int(0)
["variation_id"]=> int(0)
["quantity"]=> int(1)
["tax_class"]=> string(0) ""
["subtotal"]=> int(0)
["subtotal_tax"]=> int(0)
["total"]=> int(0)
["total_tax"]=> int(0)
["taxes"]=> array(2) {
["subtotal"]=> array(0) { }
["total"]=> array(0) { }
}
}
["data":protected]=> array(11) {
["order_id"]=> int(12291)
["name"]=> string(26) "Online marketing Duitsland"
["product_id"]=> int(11927)
["variation_id"]=> int(0)
["quantity"]=> int(1)
["tax_class"]=> string(0) ""
["subtotal"]=> string(4) "3700"
["subtotal_tax"]=> string(1) "0"
["total"]=> string(4) "3700"
["total_tax"]=> string(1) "0"
["taxes"]=> …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的想法,但我不知道如何在 WooCommerce 中实现。
在我的商店中,我启用了一些付款方式,也通过银行转帐付款。但是当客户选择银行转账时,他会看到进行转账所需的数据。但在那之后,没有选项可以在感谢页面上显示该数据,每个人都在那里寻找。
有没有一种简单的方法可以再次显示该数据?
我目前正在寻找一种在更新订单状态之前获取订单状态的方法。
例如,我的订单具有状态in-progress,我使用此函数以编程方式将订单状态更改为wc-completed:
$order->update_status( 'wc-completed' );
Run Code Online (Sandbox Code Playgroud)
当订单状态为wc-completed我有一个发送电子邮件的触发器。但我现在需要检查当前状态之前的状态是否为in-progress. 如果这是真的,我需要跳过触发器:
$latest_status = get_order_status_before_current_one($order_id);
if ($latest_status !== 'in-progress') {
// Triggers for this email.
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ), 1, 2 );
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能达到这个目标?
当订单状态改变时,我试图阻止 woo-commerce 发送邮件。这些订单来自亚马逊,我的插件将其从亚马逊同步到 woo-commerce。这样做时,来自亚马逊和 woo-commerce 的邮件都去了,这激怒了客户。因此,当我的插件更改状态时,我想停止停止电子邮件功能。更改状态的代码是
$WooOrder = wc_get_order($value->post_id);
$WooOrder->set_address($OrderData['billing'], 'billing')
$WooOrder->update_status($wooOrderStatus) // $wooOrderStatus is set above
Run Code Online (Sandbox Code Playgroud)
是否可以设置任何标志来避免发送邮件?
任何类型的帮助都受到高度赞赏。