我需要创建一个向我的插件WooCommerce Dymo Print返回值的函数。它要求$order_id,$label和$object。该$object是场我需要的价值回归。
我创建了以下代码:
add_filter('wc_dymo_order_function', 'wpf_dymo_order_output',10,3);
function wpf_dymo_order_output( $order_id, $label, $object ) {
if($label=='shipping' && $object='DEL_DATE') {
//Get order from order ID
$order=wc_get_order($order_id);
$del_date='';
$order_data = $order->get_data(); // The Order data
$order_del_date = $order_data['delivery_date'];
//Return a list (string) of all product inside this order, make sure it's well formatted before printing.
return $order_del_date;
} else {
//Return order_id if is not correct label and object
return '';
}
}
Run Code Online (Sandbox Code Playgroud)
但是,它似乎不起作用,我认为是因为delivery_date嵌套在数组中,并且我没有正确获取它。 …
我试图让woocommerce谢谢您的页面order_id。使用下面的代码。但是不幸的是我听不懂。
add_action( 'woocommerce_thankyou', 'bbloomer_check_order_product_id');
function bbloomer_check_order_product_id( $order_id ){
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item['product_id'];
if ( $product_id == XYZ ) {
// do something
}
}
}
Run Code Online (Sandbox Code Playgroud) 使用WooCommerce,在function.php提交新订单后,我有以下钩子:
add_action( 'woocommerce_new_order', 'create_job_openings');
function create_job_openings($order_id) {
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach ($order->get_items() as $key => $item) {
$product_name = $item['name'];
var_dump($product_name);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码不给我任何输出i'e它不是里面进入foreach,这就是为什么循环var_dump()没有给我任何的输出,但如果我提到了order_id专门喜欢create_job_openings($order_id=517)它的作品,即使我尝试呼应$order_id前foreach环,它给我的order_id,那么为什么它不进入foreach循环?
注意:当我var_dump($items);在foreach循环之前尝试给它时
array(0) {
}
Run Code Online (Sandbox Code Playgroud)
为什么即使在新订单生成后有产品,也无法获得产品详细信息?
在 Woocommerce 中,我想在第一次创建订单之前在“结账”页面上隐藏“paypal”网关,只显示“货到付款”网关(标记为Reserve)。
另一方面,在结帐/订单支付页面上,当订单状态为“待处理”时,隐藏“预订”网关并显示“paypal”。(当我们手动将订单状态更改为“待处理”并将带有付款链接的发票发送给客户时,就会发生这种情况)。
我认为应该通过检查订单状态并使用woocommerce_available_payment_gateways过滤器挂钩来完成。但我在获取当前订单状态时遇到问题。
另外,我不确定用户在结账页面上新创建的订单的状态是什么,但该订单仍然没有显示在管理后端中。
这是我不完整的代码:
function myFunction( $available_gateways ) {
// How to check if the order's status is not pending payment?
// How to pass the id of the current order to wc_get_order()?
$order = wc_get_order($order_id);
if ( isset($available_gateways['cod']) && /* pending order status?? */ ) {
// hide "cod" gateway
} else {
// hide "paypal" gateway
}
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试修复这个不受支持的 SagePay 插件中的一些已弃用的功能。
如何替换 WooCommerce 中以下已弃用的代码片段?
foreach ($order->get_items() as $item) {
if ($item['qty']) {
$product = $order->get_product_from_item($item);
Run Code Online (Sandbox Code Playgroud)
我可以看到这是它的替代品:
@deprecated 在未来版本中添加弃用通知。替换为
$item->get_product()
但仅仅改变它是$product = $item->get_product();行不通的。我也尝试将该行更改为:
$product = wc_get_product($item['id']);
但它会在结帐过程中导致内部服务器错误。
我目前正在自定义客户在我的网站上购买后收到的电子邮件(客户处理订单,客户完成订单等)。我已经将电子邮件文件夹从Woocommerce复制到了我的孩子主题。
我正在做的事情是使用自己的模板,然后使用Woocommerce类/ API /函数引入客户订单的相关详细信息。
到目前为止,我已经设法添加了以下信息:
我主要通过使用变量function / class $ order(IE id;?>,billing_first_name;?>)来完成此操作
我的问题是我无法成功显示产品/商品(个人)的价格。我已经寻找并搜索了实现此目的的所有方法,但是到目前为止,我尝试过的所有方法都失败了。
我在打印小计,运输,付款方式和总计(总成本)时也遇到了麻烦。也许我会以错误的方式进行操作?
这些是我用来引导我的链接
https://businessbloomer.com/woocommerce-easily-get-product-info-title-sku-desc-product-object/
任何帮助都将是极好的。这是我的代码...
<?php
foreach ($order->get_items() as $item_id => $item_data) {
$product = $item_data->get_product();
//PRODUCT NAME
$product_name = $product->get_name();
echo $product_name// THIS WORKS AND PRINTS CORRECTLY
//PRODUCT QUANTITY
$get_quantity = WC_Order_Item::get_quantity();
echo $get_quantity // THIS WORKS AND PRINTS CORRECTLY
//PRODUCT PRICE
$get_price = new WC_Order_Item_Fee::get_amount( $context );
echo $get_price // THIS DOES NOT WORK
// TRYING BELOW ALSO DOES NOT …Run Code Online (Sandbox Code Playgroud) 我正在使用“如何在 Woocommerce 中获取最新订单 ID ”答案代码,该代码通过自定义函数返回最后一个订单get_last_order_id()。
这是我获取订单商品的代码尝试:
<?php
$latest_order_id = get_last_order_id(); // Last order ID
$order = wc_get_order( $latest_order_id ); // Get an instance of the WC_Order object
$order_details = $order->get_data(); // Get the order data in an array
$order_status = esc_html( wc_get_order_status_name( $order->get_status() ) );
$order_items = $order_details['line_items'];
?>
Run Code Online (Sandbox Code Playgroud)
然后我在这段代码中使用它:
<div class="row last-order">
<div class="col-md-7">
<ul>
<?php
foreach ($order_items as $product_name) { ?>
<li><?php echo $product_name['name']; ?></li>
<?php
}
?>
</ul>
</div>
<div class="col-md-4 order-status-box"> …Run Code Online (Sandbox Code Playgroud) 在带有下面代码的 WooCommerce 中,我使用随机密码创建新的 WP_User并将用户角色设置为“客户”(我想在购买时自动创建帐户)。然后我WC_Emails用来向买家发送登录详细信息。在那种情况下,我需要简单的密码,但我真的不知道为什么附加所有其他数据(用户名、姓名等),但电子邮件通知中的密码仍然为空。
我的代码是:
// random password with 12 chars
$user_pass = wp_generate_password();
// create new user with email as username & newly created pw
$user_id = wp_create_user( $order_email, $user_pass, $order_email );
$user_id_role = new WP_User($user_id);
$user_id_role->set_role('customer');
$wc = new WC_Emails();
$wc->customer_new_account($user_id, $user_pass);
//WC guest customer identification
update_user_meta( $user_id, 'guest', 'yes' );
update_user_meta( $user_id, 'first_name', $order->billing_first_name );
update_user_meta( $user_id, 'last_name', $order->billing_last_name );
//user's billing data
update_user_meta( $user_id, 'billing_address_1', $order->billing_address_1 );
update_user_meta( $user_id, 'billing_address_2', $order->billing_address_2 ); …Run Code Online (Sandbox Code Playgroud) 在我的WooCommerce网站上,我正在使用此插件WooCommerce为客户取消订单,允许客户根据付款类型和时间取消订单。但是取消按钮仅出现在“ woocommerce_order_details_after_order_table”上。
我希望此取消按钮显示在“查看”按钮附近的“我的帐户”>“订单列表”中:

我试图编辑插件并添加以下代码: add_filter('woocommerce_my_account_my_orders_actions', array($this, 'order_cancel_button'), 10, 2);
但这不起作用:“查看”按钮消失了,“取消”按钮没有显示。
这是完整的代码:
<?php
/**
* Plugin Name: WooCommerce Order Cancel For Customers
* Plugin URI: https://wpmanageninja.com/plugins/order-cancel-for-customers-woocommerce
* Description: A tiny plugin that will enable customers to cancel woocommerce order within a certain amount of time.
* Version: 1.0
* Author: Techjewel
* Author URI: https://wpmanageninja.com
* Requires at least: 4.4
* Tested up to: 4.8
*
* Text Domain: wco
*
*/
// If this file is called …Run Code Online (Sandbox Code Playgroud) 我看到当我查看订单时,如果没有整个订单,它将显示已退款的特定商品。
是否有一种方法可以找到WC_Order_Item_Product是否已退款的商品?此外,有没有办法获得显示在订单视图中项目下方的折扣金额?
我目前正在手动执行此操作,但是如果已经有它的功能,我宁愿使用它。