php - WooCommerce 更新后,不再包含自定义计费字段
问题描述
在更新 WooCommerce 和 WordPress 后,许多自定义设置被覆盖,因此我试图恢复与旧版本相同的功能。(使用 childtheme 所以为什么它首先丢失了我不明白)修复了除此之外的所有内容。在结帐时的帐单信息中,缺少几个字段,默认的 company_name 我又开始工作了,由于某种原因,它在主题 functions.php 中被停用。但是,为 IVA 编号和组织编号保留了两个自定义字段。
因此,我使用了 WooCommerce 的 Checkout Manager 将自定义字段添加到帐单信息中。它适用于结帐页面,信息最终出现在订单上。但它不会出现在感谢页面上,更重要的是它不会出现在给客户的电子邮件中。
尝试将其添加到主题 functions.php 但没有运气。
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
$fields['billing_wooccm13'] = array(
'label' => __( 'Moms/IVA' ),
'value' => get_post_meta( $order->id, 'billing_wooccm13', true ),
);
return $fields;
}
并且还尝试了这个:
add_action('woocommerce_email_customer_details','add_custom_checkout_field_to_emails_notifications', 25, 4 );
function add_custom_checkout_field_to_emails_notifications( $order, $sent_to_admin, $plain_text, $email ) {
$output = '';
$billing_field_testing = get_post_meta( $order->id, 'billing_wooccm13', true );
if ( !empty($billing_wooccm13) )
$output .= '<div><strong>' . __( "Some text:", "woocommerce" ) . '</strong> <span class="text">' . $billing_wooccm13 . '</span></div>';
echo $output;
}
任何想法如何去做?
解决方案
由于 WoooCommerce 3$order->id
被替换为$order->get_id()
……还有其他一些方法。
确保您的自定义字段的元键是billing_wooccm13
(因为它可以改为以下划线开头_billing_wooccm13
)。
尝试以下操作:
add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
if ( $value = $order->get_meta( 'billing_wooccm13' ) ) {
$fields['billing_wooccm13'] = array(
'label' => __( 'Moms/IVA' ),
'value' => $value,
);
}
return $fields;
}
代码位于活动子主题(或活动主题)的 functions.php 文件中。它应该工作。
或者这也是:
add_action('woocommerce_email_customer_details','add_custom_checkout_field_to_emails_notifications', 25, 4 );
function add_custom_checkout_field_to_emails_notifications( $order, $sent_to_admin, $plain_text, $email ) {
if ( $value = $order->get_meta( 'billing_wooccm13' ) ) {
echo '<div><strong>' . __( "Some text:", "woocommerce" ) . '</strong> <span class="text">' . $value . '</span></div>';
}
}
代码位于活动子主题(或活动主题)的 functions.php 文件中。它应该工作。
推荐阅读
- python - 如何定义在 Python 控制台上显示 DataFrame 时以哪种格式显示 `datetime` 值?
- java - 无法将值更新到数据库中的表
- neo4j - 是否可以在 Neo4j 中的节点之间创建未指定的类型关系
- jquery - Bootstrap v3.3.7:不能做下拉导航栏
- ionic-framework - Ionic - setRoot 和 push 之间的区别
- python - Python Pandas 保留特定值的第一次出现并删除具有相同特定值的其余行
- react-native - React Native [Section List ] 在部分上动态添加项目
- python - 将数据框系列中的分数转换为浮点数
- python - 如何在列表中递增并用它们的计数替换某些值
- r - 如何检查日期是否在 R 中的两个值之间?