我需要动态地将装运和装运跟踪添加到订单中,它需要动态,因为我们将批量执行,您能给我一些帮助吗?
编辑:
用户将看到一个包含订单列表的页面,然后他将输入每个订单的跟踪编号并提交表单,因此我需要获得一个已知的运营商并通过此运营商发送所有订单.
我的WooCommerce单品上有自定义字段.它发送到购物车罚款,它在结账时显示罚款,它在仪表板中按顺序显示.
我现在要做的是将值设置为订单页面中的自定义字段,以便我能够在需要时修改文本.出于某种原因,当我提交表单时,此步骤无效.
我在我的functions.php文件中使用的代码:
// Add the field to the product
add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
function my_custom_checkout_field() {
echo '<div id="my_custom_checkout_field"><h3>'.__('My Field').'</h3>';
echo '<label>fill in this field</label> <input type="text" name="my_field_name">';
echo '</div>';
}
// Store custom field
function save_my_custom_checkout_field( $cart_item_data, $product_id ) {
if( isset( $_REQUEST['my_field_name'] ) ) {
$cart_item_data[ 'my_field_name' ] = $_REQUEST['my_field_name'];
/* below statement make sure every add to cart action as unique line item */
$cart_item_data['unique_key'] = md5( microtime().rand() );
}
return $cart_item_data;
}
add_action( 'woocommerce_add_cart_item_data', 'save_my_custom_checkout_field', …Run Code Online (Sandbox Code Playgroud) 我想在WooCommerce电子邮件模板中发送电子邮件时获取产品描述和产品名称.
我可以$order_id = trim(str_replace('#', '', $order->get_items()));使用此代码获取产品ID
但是当我试图获得它的描述和产品名称时,我无法做同样的事情.
我的代码:
$order = new WC_Order($order_id);
foreach($order->get_items() as $item){
$product_description = get_post($item['product_id'])->post_content;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能使它工作?
谢谢
我在function.php中添加了这个我想要做的是在订单设置完成之后我正在尝试向用户发送短信但是当我将其设置为已完成时它会给出500错误
add_action( 'woocommerce_order_status_completed', 'my_function' );
/*
* Do something after WooCommerce sets an order on completed
*/
function my_function($order_id) {
foreach ($order->get_items() as $item_id => $item) {
$product_name = $item['name']; // product name
$product_id = $order->get_item_meta($item_id, '_product_id', true); // product ID
$product_description = get_post($product_id)->post_content; // Product description
}
file_get_contents('http://144.76.39.175/api.php?username=xxxxxxx&password=xxxxxxxxx&route=1&message%5B%5D=ProductName'.$product_name.'&sender=xxxxx&mobile%5B%5D=xxxxxx');
}
Run Code Online (Sandbox Code Playgroud) 情况就是这样.我有一个用作市场的woocommerce网站.我正在销售游戏,因为有些购买者会收到蒸汽钥匙.为此,我正在研究一个关键的归属系统,所以通过进入一个页面,密钥将是用户的属性.
为此,我想检查当前用户(登录和页面上)所做的所有订单,并检查他购买的游戏.
我在这里找到了一些非常有用的信息:如何获取WooCommerce订单详情
但是,我无法获得当前用户的所有订单.我首先考虑发出一个SQL请求,但是我没有在订单和用户之间找到数据库上的链接.
你有领导吗?
如何在WooCommerce中更改电子邮件发件人地址和姓名以获取特定的电子邮件通知?
例如:
仅为客户处理订单电子邮件通知更改发件人姓名和电子邮件地址.
但不适用于所有电子邮件通知,仅针对特定电子邮件通
我正在尝试添加一个$order = wc_create_order();由用户定义的产品价格。一个特定的产品被添加到订单中,它已经有一个默认价格,需要被用户输入的值覆盖。
我尝试使用woocommerce_before_calculate_totals函数但没有运气。我认为它不起作用,因为产品直接添加到订单中而没有添加到购物车中。
我也试过使用set_total( $value, $deprecated = '' ),比如
$order = wc_create_order();
$order->set_total($amount); //where the $amount is my custom price.
Run Code Online (Sandbox Code Playgroud)
但订单价值不会改变。有没有其他方法可以实现相同的目标?
我正在开发一个直接创建订单(无购物车)并应用优惠券的插件。在 woo API 的 3.0 版中,该函数add_coupon()已被弃用,取而代之的是WC_Order_Item_Coupon您添加到订单中的对象。
创建优惠券
$coupon = new WC_Order_Item_Coupon();
$coupon->set_props(array('code' => $coupon, 'discount' => $discount_total,
'discount_tax' => 0));
$coupon->save();
Run Code Online (Sandbox Code Playgroud)
这是成功的。我可以通过调用来验证$coupon->get_discount()。
然后我将优惠券添加到订单并重新计算总数:
$order->add_item($item);
$order->calculate_totals($discount_total);
$order->save();
Run Code Online (Sandbox Code Playgroud)
登录 wp-admin 我可以看到带有优惠券代码的订单。但是,优惠券对行项目或总计没有影响。
是否误解了 api v3.0 打算如何处理优惠券?
我正在“即时”创建 Woocommerce 总计,因为我的购物车项目是从另一个 CMS 导入的。
目前,我无法为每个订单设置自定义“费用”,然后将订单标记为“暂停”:
$order->set_date_created($creation_tsz);
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->set_currency('GBP');
$order->add_fee('Imported Total', $imported_total_here);
$order->set_fee();
$order->calculate_totals();
$order->update_status('on-hold');
Run Code Online (Sandbox Code Playgroud)
任何关于此的曲目将不胜感激。
我实质上是在尝试复制购物车页面上的功能,用户可以在其中添加他们的商品zip code,并计算可用的运费,但是我试图从后端在已经创建的订单中进行操作。
我找不到直接从WC_Order实例执行此操作的方法,因此,我的下一个优点是清除购物车会话,将订单中的所有项目添加到购物车会话,然后尝试进行计算。
到目前为止,这就是我所拥有的。我一直坚持如何计算整个订单的价格。
$order_id = isset($_POST['order_id'])?$_POST['order_id']:0;
$country = isset($_POST['country'])?$_POST['country']:0;
$state = isset($_POST['state'])?$_POST['state']:0;
$postcode = isset($_POST['postcode'])?$_POST['postcode']:0;
$city = isset($_POST['city'])?$_POST['country']:0;
$order = wc_get_order( $order_id );
$order_items = $order->get_items();
// Don't know if this would save country of logged in user, or only create a temporary guest user session which is what I'd need
if ( $country != '' ) {
WC()->customer->set_billing_location( $country, $state, $postcode, $city );
WC()->customer->set_shipping_location( $country, $state, $postcode, $city );
} else {
WC()->customer->set_billing_address_to_base();
WC()->customer->set_shipping_address_to_base(); …Run Code Online (Sandbox Code Playgroud)