我正在尝试允许用户从他们的“我的帐户”面板更新他们订阅的行项目。我可以从订阅 ID 获取他们的订阅并向他们显示更新表。现在,我向他们展示了他们订阅中我通过的产品项目
$subscription = wcs_get_subscription($_GET['subscription']);
$subscription_items = $subscription->get_items();
Run Code Online (Sandbox Code Playgroud)
我想做的是允许用户更新他们产品的数量。因此,如果他们更新数量,我想更新订阅的项目数量,以便使用更新的数量生成未来的订单。我看到WC_Abstract_Order课堂上有 update_product 方法。我认为这可以使用,但我对评论中的注释感到困惑:
* Update a line item for the order.
*
* Note this does not update order totals.
Run Code Online (Sandbox Code Playgroud)
使用它时是否需要重新计算总数?当数量为 0 时,我还需要删除订单项。这可能吗?
因为我没有看到删除项目方法。
谢谢
在 WooCommerce 中,我使用一个特殊的主题来处理摩托车和踏板车租赁服务的预订。我想获取订单相关数据。我试图发送当电子邮件通知发送给客户的短信completed,on hold,pending和**processing**订单状态。
例如,我使用下面的代码在 SMS 中输出我需要的数据:
$order = new WC_Order($order_id);
$status = $order->get_status(); // order status
if( 'completed' == $status || 'processing' == $status || 'pending' == $status || 'on-hold' == $status ){
$user_phone = get_post_meta($order_id, '_billing_phone', true);
foreach ($order->get_items() as $item_id => $item) {
$product_id = $order->get_item_meta($item_id, '_product_id', true); // product ID
$product_name = get_post($product_id)->post_title; // Product description
// Related Booking data to insert in SMS
$book_check_in = $order->get_item_meta( $item_id, …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的 woocommerce 操作来调用自定义函数,但由于某种原因,它在每个订单上都会被触发两次。有谁知道这可能是为什么或如何解决它以便每个订单只调用一次?
add_action( 'woocommerce_thankyou', 'parent_referral_for_all', 10, 1 );
function parent_referral_for_all( $order_id ) {
....
}
Run Code Online (Sandbox Code Playgroud)
更新
我以为这个动作被触发了两次,但我现在不太确定。我正在使用此操作在affiliatewp 插件中添加另一个推荐,该插件添加了两次,但我对“谢谢”的回声只出现一次。
一切都按预期工作,只是推荐(及其相关的订单说明)被添加了两次。
任何帮助将不胜感激。
那个完整的功能:
function parent_referral_for_all( $order_id ) {
//Direct referral
$existing = affiliate_wp()->referrals->get_by( 'reference', $order_id );
$affiliate_id = $existing->affiliate_id;
//Total amount
if( ! empty( $existing->products ) ) {
$productsarr = maybe_unserialize( maybe_unserialize( $existing->products ) );
foreach( $productsarr as $productarr ) {
$bigamount = $productarr['price'];
}
}
//Parent amount
$parentamount = $bigamount * .1;
$affiliate_id = $existing->affiliate_id;
$user_info = get_userdata( affwp_get_affiliate_user_id( $existing->affiliate_id …Run Code Online (Sandbox Code Playgroud) 我对 WordPress 非常陌生,并且已经使用 WooCommerce 创建了一个电子商务商店。
客户下订单后,我收到一封电子邮件,客户收到一封电子邮件——一封让我说他们订购了什么,另一封作为感谢电子邮件给他们。
在这封感谢邮件中,在我的functions.php 文件中,我学会了更改标题的主题以包含其名称,例如:
//add the first name of the person to the person getting the reciept in the subject of the email.
add_filter('woocommerce_email_subject_customer_processing_order','UEBC_change_processing_email_subject', 10, 2);
function UEBC_change_processing_email_subject( $subject, $order ) {
global $woocommerce;
$subject = 'Thanks for your ' . get_bloginfo( 'name', 'display' ) . ' Order, '.$order->billing_first_name .'!';
return $subject;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码片段工作正常,并且只显示给客户,而不是我。例如“感谢您订购 ABCD 服装订购约翰!”。在电子邮件的正文中,我试图将其作为一个简短的感谢消息来个人化,但是,当我发送消息时,我使用了钩子:
add_action( 'woocommerce_email_before_order_table', 'custom_add_content', 20,1 );
Run Code Online (Sandbox Code Playgroud)
我知道因为我使用了woocommerce_email_before_order_table钩子,所以自定义函数将在电子邮件正文中发送给客户和我自己。
我想知道,Woocommerce 是否提供了一个钩子,以便自定义功能只会在电子邮件正文中发送给客户?
例如:woocommerce_email_header_customer_processing_order或者有那个意思的词?
谢谢
我需要在订单完成时执行操作。
我试过这个:
function mysite_woocommerce_payment_complete( $order_id ) {
error_log("callback fired");
}
add_action( 'woocommerce_payment_complete', 'mysite_woocommerce_payment_complete' );
Run Code Online (Sandbox Code Playgroud)
……钩子没有开火。我也试过woocommerce_order_status_changed,它在我下订单时执行操作,但当我将订单标记为已完成时它什么也不做。
但是当我将订单标记为已完成时,我会收到有关完成订单的电子邮件。
谢谢!
编辑:
我也试过woocommerce_order_status_changed,这样:
function mysite_woocommerce_payment_complete($order_id, $old_status, $new_status ) {
error_log("$old_status / $new_status \n");
}
add_action( 'woocommerce_order_status_changed', 'mysite_woocommerce_payment_complete', 99, 3 );
Run Code Online (Sandbox Code Playgroud)
但它在购买时触发(我选择了银行转帐)并显示:“待处理/暂停”,但不是真的 - 请参阅 edi2不会触发从“暂停”到“已完成”的手动后端更改。既不是通过复选标记也不是在单订单界面。
Edit2
woocommerce_order_status_changed并woocommerce_order_status_completed工作,它只将我的测试“错误”输出到 debug.log,而不是出于某种原因输出到 error_log。在woocommerce_payment_complete我以前使用的并不适用于像银行转账,这就是为什么没有奏效的方法。感谢@helgatheviking 提供快速正确的答案
WooCommerce 3.0 更新对我并不友好。我添加了一个自定义的必填字段来结帐域名,但现在无法弄清楚如何保存它。此代码仍然正确添加字段:
add_action( 'woocommerce_after_order_notes', 'add_domain_checkout_field' );
function add_domain_checkout_field( $checkout ) {
echo '<div id="add_domain_checkout_field"><h2>' . __('Domain') . '</h2>';
woocommerce_form_field( 'sitelink_domain', array(
'type' => 'text',
'required' => true,
'class' => array('my-field-class form-row-wide'),
'label' => __('Domain where SiteLink will be installed'),
'placeholder' => __('Enter your URL'),
), $checkout->get_value( 'sitelink_domain' ));
echo '</div>';
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试以这种方式保存它:
add_action( 'woocommerce_checkout_create_order', 'add_domain_to_order_meta', 10, 2 );
function add_domain_to_order_meta( $order, $data ) {
if ( ! empty( $_POST['sitelink_domain'] ) ) {
$order->add_meta_data( 'ssla_sitelink_url', sanitize_text_field( $_POST['sitelink_domain'] ) );
} …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) 在 WooCommerce 中,对于登录用户,Thankyou(已收到订单)页面会显示客户详细信息,例如姓名、地址和电子邮件,但在客户未注册时不会显示任何信息。
如何确保非注册用户在支付成功完成后,可以在Thankyou(已收到订单)页面上看到他们的详细信息,就像注册用户一样?
为什么非注册用户的Thankyou(已收到订单)页面上不显示客户详细信息?
在用户点击结帐后,我似乎找不到用于更改总数(或购物车的任何变量)的钩子。因此,例如,用户提交“结帐”表单,然后我需要做一些检查并相应地更改总数。
我该怎么做,我该使用哪个挂钩?
我想在Woocommerce的帐户查看订单页面上添加图片。有人可以获取图片,但是尺寸太大,我不知道该在哪里添加此代码:
<?php
// Get a list of all items that belong to the order
$products = $order->get_items();
// Loop through the items and get the product image
foreach( $products as $product ) {
$product_obj = new WC_Product( $product["product_id"] );
echo $product_obj->get_image();
}
?>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激
这是我想添加产品图片的“查看订单”页面上的位置: