我在 WooCommerce 的“订单”部分添加了一个自定义列,用于运输邮政编码。该列及其值正确显示。
我无法弄清楚的是如何使该字段的排序工作(单击列标题)。我可以找到使用钩子“manage_edit-shop_order_sortable_columns”提到的其他代码示例,但这似乎不适用于该领域。
注意:我已经看到了关于此的其他 StackOverflow 问题,但似乎没有一个排序工作。
/**
* ADD ZIP CODE TO WOOCOMMERCE ORDERS LIST
*/
// Add column (working)
add_filter( 'manage_edit-shop_order_columns', 'custom_woo_columns_function' );
function custom_woo_columns_function( $columns ) {
$new_columns = ( is_array( $columns ) ) ? $columns : array();
unset( $new_columns[ 'order_actions' ] );
// all of your columns will be added before the actions column
$new_columns['zipcode'] = 'Zip Code';
//stop editing
$new_columns[ 'order_actions' ] = $columns[ 'order_actions' ];
return $new_columns;
}
// Change order of columns (working) …Run Code Online (Sandbox Code Playgroud) 我想改变 每一个 订单 从与状态woocommerce “HOLD-ON” 为“处理” 用PHP。
我已经尝试在functions.php文件中编写一个函数,但是我失败了。
如何在 Woocommerce 中自动将订单状态从“保留”更改为“处理”?
在 Woocommerce 中,我如何在订单详细信息(以及 Wordpress 的后端)中显示产品类别名称。也可以让它们出现在电子邮件通知中。
我希望将 WooCommerce 订单 ID 作为短代码引用,以便在收到的订单页面中轻松使用以生成动态链接。
function my_order_id( $atts ) {
echo $order->get_id();
}
add_shortcode( 'my_order_id', 'my_order_id');
Run Code Online (Sandbox Code Playgroud) 我正在尝试在 WooCommerce 中为每个订单项获取税号。
例如:2x 产品 1 - 19 % MwSt。(含税) 4x 产品 2 - 19 % MwSt。(税) 1x 产品 2 - 19 % MwSt。(税)
所以我在 woocommerce 设置中添加了税“19%(税)”作为标准值和“7%(税)”作为减税。我还设置了我想在 WooCommerce 中“不含税”显示和输入价格。
现在我用这两个项目(数字和可下载)下订单,然后我尝试获取每个订单项目的税值。
$wc_order = wc_get_order(143);
foreach ($wc_order->get_items(array('line_item')) as $item_id => $line_item) {
$order_product_detail = $line_item->get_data();
$item_tax_class = $order_product_detail['tax_class'];
$item_subtotal_tax = $order_product_detail['subtotal_tax'];
$item_total_tax = $order_product_detail['total_tax'];
$item_taxes_array = $order_product_detail['taxes'];
var_dump($item_tax_class);
var_dump($item_subtotal_tax);
var_dump($item_total_tax);
var_dump($item_taxes_array);
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
string(0) "" string(4) "0.76" string(6) "0.2185" array(2) { ["total"]=> array(1) { [1]=> string(6) "0.2185" } ["subtotal"]=> array(1) { [1]=> …Run Code Online (Sandbox Code Playgroud) 我在此代码中有一个错误(按顺序添加编辑页面可编辑的自定义计费字段):
add_filter( 'woocommerce_admin_billing_fields' , 'order_admin_custom_fields' );
function order_admin_custom_fields( $fields ) {
global $theorder;
$fields['billing_address_3'] = array(
'label' => __( 'Home', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Home', true ),
'show' => true,
'wrapper_class' => 'form-field-wide',
'style' => '',
);
$fields['billing_address_4'] = array(
'label' => __( 'Entrance', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Entrance', true ),
'show' => true,
'wrapper_class' => 'form-field-wide',
'style' => '',
);
$fields['billing_address_5'] = array(
'label' => __( 'Floor', 'woocommerce' ),
'value'=> get_post_meta( $theorder->get_id(), 'Floor', true ),
'show' => …Run Code Online (Sandbox Code Playgroud) 我正在做一个项目,但我一直坚持将 Woocommerce 产品类型定义为“简单”、“可变”、“分组”或“外部”……
我想要实现的目标:
在“谢谢”页面上,上面写着“谢谢。您的订单已收到。 ”。
如果产品是“简单的”,而另一个文本是产品是可变的、分组的或外部的,我想在那里显示一个特定的文本,例如:
if (product->get_type() == 'simple') {// (for simple product)
//show a text
}else {// (for variable, grouped and external product)
//show another text
}
Run Code Online (Sandbox Code Playgroud)
我已经能够使用这个:
function custome_tank_you_text($order_id) {
$order = new WC_Order( $order_id );
$items = $order->get_items();
foreach ( $items as $item ) {
$product = wc_get_product( $item['product_id'] );
$product->get_type();
}
if( $product == 'simple'){ ?>
<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you for topping up your wallet. It has …Run Code Online (Sandbox Code Playgroud) 我在我的 woocommerce 订单页面中添加了一个自定义操作,如下所示,我还有一个自定义订单字段“餐数”。现在我想要的是当我批量选择订单并使用该自定义操作时,餐食数量应减少 1。
例如,如果订单 ID 1 和 2 分别有 15 和 12 餐,则在使用该操作后它应该变成 14 & 11 ...
我的订单页面截图,我创建的自定义钩子和自定义订单字段:
我的代码:
add_filter( 'bulk_actions-edit-shop_order', 'decrease_number_of_meals_by_1' );
function decrease_number_of_meals_by_1( $bulk_actions ) {
$bulk_actions['decrease_number_of_meals'] = 'Decrease Number of Meals by 1';
return $bulk_actions;
}
add_action( 'admin_action_decrease_number_of_meals', 'fire_my_hook' );
function fire_my_hook() {
if( !isset( $_REQUEST['post'] ) && !is_array( $_REQUEST['post'] ) )
return;
foreach( $_REQUEST['post'] as $order_id ) {
$order = new WC_Order( $order_id );
$no_of_meals = $order->get_post_meta( $order_id, '_wc_acof_{3}', true );
}
}
Run Code Online (Sandbox Code Playgroud)
我被困在这里,不知道如何进一步做。
请指导我如何实现这一目标。
我需要帮助解决与插件“WooCommerce Pay for Payment”相关的问题,该插件计算运费中的一些额外费用。问题是,这个插件会自动设置“处理”状态,这会导致感谢电子邮件付款(在本地付款的情况下)并且不发送有关新订单的电子邮件通知,因此客户感到困惑(我没有发送任何钱,我收到了电子邮件“感谢您的付款”)。
我尝试了这个解决方案:当订单从处理到待处理时设置 WooCommerce 订单状态
但它只会将订单状态更改回“暂停”,但无论如何都会发送电子邮件感谢付款。
我只需要在每封新订单电子邮件中向客户发送有关新订单的一件事,仅此而已(我想将状态更改为手动“处理”)。
感谢您的帮助,我不知道如何解决,因为我找不到导致插件状态更改的 PHP 文件。
编辑:对不起大家。这是woocommerce插件中的COD问题。不支付我提到的付款。Woocommerce COD 自动设置“处理”状态。
我在 github 上找到了解决方案:here
它的第一个代码。
基于对这个问题的答案,这个代码的工作对我罚款:
function sv_wc_cod_order_status( $status ) {
return 'on-hold';
}
add_filter( 'woocommerce_cod_process_payment_order_status', 'sv_wc_cod_order_status', 15 );
Run Code Online (Sandbox Code Playgroud) 我需要发送,当我手动设置从订单状态的客户电子邮件通知processing到on-hold状态。我已将以下操作挂钩添加到我的functions.php文件中:
add_action( 'woocommerce_order_status_processing_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
Run Code Online (Sandbox Code Playgroud)
它不工作(没有显示在 WP 邮件日志中),即使在 woocommerce 设置中启用了这个特定的电子邮件通知,并且如下所示的类似钩子工作得很好:
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ), 10, 2 );
Run Code Online (Sandbox Code Playgroud)
环境:Woocommerce v.3.5.1 Wordpress v.4.9.9 PHP 5.6
任何帮助将非常感激。