我有一些订单处于处理状态。我知道 Magento 不允许取消发票订单,只能创建贷项凭证,但我需要更改它。我需要做一些事情来撤消发票的创建并将其返回到“待处理”,或者只是取消它。
我使用 Woocommerce,实际上我只收到一封电子邮件的订单通知。我希望根据客户所在位置通过两封不同的电子邮件收到有关订单的通知:
Mail #1 (mail1@mail.com),Mail #2 (mail2@mail.com)。我在网上寻找一些函数,但我发现只有发送到两个电子邮件地址的函数,但没有任何 If 条件。
我需要的是这样的东西:
if ($user->city == 'Germany') $email->send('mail1@mail.com')
else $email->send('mail2@mail.com')
Run Code Online (Sandbox Code Playgroud)
我可以使用哪个钩子来使其工作?
谢谢。
我使用自定义结帐字段在我的 woocommerce 商店的结帐页面上为我的客户提供“运送到公司地址”选项。大部分代码工作正常,但我无法显示他们是否选中了后端管理订单详细信息中的复选框。
我已向我的 woocommerce 商店添加了自定义结账字段,并将数据保存到订单元:
//add custom checkout field
add_filter( 'woocommerce_after_checkout_billing_form', 'gon_business_address_checkbox_field' );
function gon_business_address_checkbox_field( $checkout ){
woocommerce_form_field( 'business_address_checkbox', array(
'label' => __('<h3 id="business_address_label">Check this box if you are shipping to a business.</h3>', 'woocommerce'),
'required' => false,
'clear' => false,
'type' => 'checkbox'
), $checkout->get_value( 'business_address_checkbox' ));
}
//update order meta
add_action('woocommerce_checkout_update_order_meta', 'gon_update_order_meta_business_address');
function gon_update_order_meta_business_address( $order_id ) {
if ($_POST['business_address_checkbox']) update_post_meta( $order_id, 'Business Address?',
esc_attr($_POST['business_address_checkbox']));
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试在管理订单部分显示此数据的地方。我尽可能密切地关注了之前的主题,但无济于事。
// Display field value on the admin order edit page
add_action( 'woocommerce_admin_order_data_after_shipping_address', …Run Code Online (Sandbox Code Playgroud) 我不是开发人员,但以某种方式设法将 Woocommerce 自定义字段添加到结帐和订单编辑页面。有类似的问题,但我找不到正确的解决方案。
\n\n自定义字段在管理订单编辑页面中可见,但不显示值,也不会添加到订单电子邮件中。
\n\n我缺少什么?
\n\n请看最后的截图。
\n\n这是所有代码的组合:
\n\n// Woocommerce - Add user custom billing fields\n// =============================================================================\n\nfunction add_woocommerce_admin_billing_fields($billing_fields) {\n $billing_fields[\'billing_birthday\'] = array(\n \'label\' => __(\'Datum rojstva\', \'woocommerce\')\n );\n $billing_fields[\'billing_socialno\'] = array(\n \'label\' => __(\'Dav\xc4\x8dna \xc5\xa1tevilka\', \'woocommerce\')\n );\n\n return $billing_fields;\n}\nadd_filter(\'woocommerce_admin_billing_fields\', \'add_woocommerce_admin_billing_fields\');\n\nfunction add_woocommerce_found_customer_details($customer_data, $user_id, $type_to_load) {\n if ($type_to_load == \'billing\') {\n $customer_data[$type_to_load . \'billing_birthday\'] = get_user_meta($user_id, $type_to_load . \'billing_birthday\', true);\n $customer_data[$type_to_load . \'billing_socialno\'] = get_user_meta($user_id, $type_to_load . \'billing_socialno\', true);\n\n }\n return $customer_data;\n}\nadd_filter(\'woocommerce_found_customer_details\', \'add_woocommerce_found_customer_details\', 10, 3);\n\nfunction add_woocommerce_billing_fields($billing_fields) …Run Code Online (Sandbox Code Playgroud) 我正在使用 Woocommerce 在 Wordpress 上管理我的产品,但用户通过 3rd 方服务付款。
我正在尝试手动创建新订单,并将其分配给当前用户。订单确实已创建并记录,但以下代码仅记录项目和时间,没有用户的详细信息:
global $woocommerce;
$address = array(
'first_name' => $_GET['FirstName'],
'last_name' => $_GET['LastName'],
'company' => $_GET['CompanyName'],
'email' => $_GET['EmailAddress'],
'phone' => $_GET['MobilePhoneNumber'],
'address_1' => '',
'address_2' => '',
'city' => '',
'state' => '',
'postcode' => '',
'country' => $_GET['countryCode']
);
$order = wc_create_order();
foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
$item_id = $order->add_product(
$values['data'], $values['quantity'], array(
'variation' => $values['variation'],
'totals' => array(
'subtotal' => $values['line_subtotal'],
'subtotal_tax' => $values['line_subtotal_tax'],
'total' => $values['line_total'], …Run Code Online (Sandbox Code Playgroud) 我已在后台订单中为每条产品线添加自定义字段:

(来源:com-pac.ovh)
我的代码:
add_action( 'woocommerce_before_order_itemmeta', 'cfwc_create_custom_field' );
function cfwc_create_custom_field() {
$args = array(
'id' => 'custom_text_field_title',
'label' => __( 'Custom Text Field Title', 'cfwc' ),
'class' => 'cfwc-custom-field',
'desc_tip' => true,
'description' => __( 'Enter the title of your custom text field.', 'ctwc' ),
);
woocommerce_wp_text_input( $args );
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我不知道如何保存这个字段。
有什么帮助吗?
在 WooCommerce 我的帐户“订单视图”页面中,我应该添加这样的视觉跟踪:

在实际页面上,要跟踪每个订单,上面的订单详细信息:
第一个问题是我不知道如何将 html 和 php 代码添加到视图订单页面我尝试在 functions.php 上添加钩子但它没有用
第二个问题是我想在查看订单页面中获取每个订单的状态(例如:处理或交付等)
这是我尝试实现它的functions.php代码:
// **
// * Add custom tracking code to the view order page
// */
add_action( 'woocommerce_view_order', 'my_custom_tracking' );
function my_custom_tracking(){
$order = wc_get_order( $order_id );
$order_id = $order->get_id(); // Get the order ID
$parent_id = $order->get_parent_id(); // Get the parent order ID (for subscriptions…)
$user_id = $order->get_user_id(); // Get the costumer ID
$user = $order->get_user(); // Get the WP_User object
echo $order_status = $order->get_status(); // Get …Run Code Online (Sandbox Code Playgroud) 我正在尝试提取添加到 WooCommerce 结账表单中的自定义字段的订单元数据。我在 PHP 文件中执行此操作,该文件用于将自定义部分添加到 WooCommerce 发送给客户的订单确认电子邮件中(即订单处理的最后阶段)。
为了做到这一点,我尝试使用 WC_Order 类和以下代码:
$my_var = get_post_meta( $order_id, 'custom_field_meta_key', true );
然而,这种方法行不通。我意识到“order_id”变量在 PHP 页面中不可用。我使用以下代码来确认这一点:
print_r(array_keys(get_defined_vars()));
以下是我得到的输出:
Array ( [0] => template_name [1] => args [2] => template_path [3] => default_path [4] => cache_key [5] => template [6] => filter_template [7] => action_args [8] => title [9] => delivery_date [10] => email )
有人可以帮助我找到获得预期结果的最佳方法吗?
我在购物车中展示我的产品没有任何税款,因为我将它们添加到购物车中的小计中。问题是我无法找到稍后在“我的订单”页面上获取用于订单的税率的方法。所以我正在寻找一种方法来获取订单结账期间使用的税率。费率可能因国家/地区而异。
我所拥有的是:
global $order;
$order->get_the_used_tax_rate_somehow();
Run Code Online (Sandbox Code Playgroud) 我真的很难让它发挥作用。我脑子里有一个想法:
能够通过常规优惠券选项卡中的额外字段将单个用户分配给优惠券代码,该字段将未分配的用户列出优惠券代码
我不想使用第三方扩展、自定义字段等。我希望我能够通过元数据做到这一点,但我失败了。不知道如何正确完成它。
在订单页面上添加两个额外的列并显示优惠券代码和分配给它的用户。
在 phpstorm 中阅读文档和 xDebugging 一段时间后,我也未能完成。
function order_sellers_and_coupons_columns_values($column)
{
global $post, $the_order;
if ($column == 'order_coupon_code') {
$coupons = $the_order->get_used_coupons(); // not sure how to get coupon object by the coupon code
echo (count($coupons)) ? $coupons[0] : '';
}
}
// even though I see the order objects have an items and coupon lines property,
// which is an object, i can't get access to it
$the_order->items["coupon_lines"]
Run Code Online (Sandbox Code Playgroud)
我不是要求现成的解决方案,而是向我展示如何完成它。
在此先感谢您的任何帮助。