如何更改循环中的 WooCommerce 产品标题,例如更改shop, category页面中的产品图块等?
我正在寻找可以帮助解决这个问题的钩子。去的时候woocommerce/content-product.php显示
do_action('woocommerce_before_shop_loop_item_title');
echo '<div class="title-wrapper">';
do_action('woocommerce_shop_loop_item_title');
echo '</div>';
Run Code Online (Sandbox Code Playgroud)
请帮忙
我想更改产品图块shop page, category page等。但在single product page, or cart, checkout页面中我不想更改标题。还有简码呢[products ids="12,34,56,"];?
我怎样才能更改标题?
wordpress woocommerce woothemes hook-woocommerce woocommerce-theming
我正在创建一个插件,在其中使用woocommerce_checkout_update_order_meta钩子添加订单项元。
我安装了一个名为WooCommerce TM Extra Product Options 的插件。
该插件使用woocommerce_checkout_create_order_line_item钩子来添加订单项元。
激活插件后,我会在订单接收页面上显示插件的元字段,但我的元信息没有显示。如果插件被停用或当我评论woocommerce_checkout_create_order_line_item操作挂钩时,我的元数据就会显示。
在 Woocommerce 中,要向客户发送短信付款信息,我需要在成功付款后激活触发器。
但我没有找到任何钩子来做
这是我的插件代码:
if ( isset( $this->options['wc_notify_customer_payment_successful_enable'] ) ) {
add_action( '####Action to be used here#######', array( &$this, 'successful_payment_notification_client' ) );
}
/* WooCommerce Successful payment notification client
*
* @param $order_id
*/
public function successful_payment_notification_client ( $order_id ) {
// Check the mobile field is empty
if ( empty( $_REQUEST['mobile'] ) ) {
return;
}
$order = new WC_Order( $order_id );
$this->sms->to = array( $_REQUEST['mobile'] );
$template_vars = array(
'%order_id%' => $order_id,
'%order_number%' => $order->get_order_number(),
'%status%' => …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何修改单个产品选项,以便产品管理员可以从下拉列表中选择产品的状况,即新的/二手的。
以下是允许产品管理员手动输入产品状况的代码。
// Enabling and Displaying Fields in backend
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '<div class="options_group">';
woocommerce_wp_text_input( array( // Text Field type
'id' => '_Stan',
'label' => __( 'Stan', 'woocommerce' ),
'placeholder' => 'i.e: nowa; uzywana...',
'desc_tip' => 'true',
'description' => __( 'Podaj stan plyty.', 'woocommerce' )
) );
echo '</div>'; // Closing </div> tag HERE
}
// Save Fields values to database when submitted (Backend)
add_action( 'woocommerce_process_product_meta', 'woo_save_custom_general_fields' );
function woo_save_custom_general_fields( $post_id ){ …Run Code Online (Sandbox Code Playgroud) 我找到了一种方法来更改占位符,但不更改 woocommerce 中结账输入字段的标签。
我想更改 的标签adress_field_2。
这是我的尝试,没有改变任何东西。我尝试了 [label] 和 [label_class] 但这不起作用......
add_filter( 'woocommerce_default_address_fields', 'new_checkout_field_label', 10, 1 );
function new_checkout_field_label( $address_fields ) {
$address_fields['address_2']['placeholder'] = __( '', 'woocommerce' );
$address_fields['address_2']['label'] = __( 'Apt, Unit, Etc (optional)', 'woocommerce' );
return $address_fields;
}
Run Code Online (Sandbox Code Playgroud) 我希望在客户方的订单历史记录中显示最后的订单备注,目前只能通过 Woocommerce 中的管理员查看。
这样他们就可以在订单设置完成后查看我们添加的跟踪号码。
https://example.com/my-account/view-order/135/
Run Code Online (Sandbox Code Playgroud)
我们首先通过 Woocommerce API 将订单设置为“完成”,然后添加带有跟踪链接的订单备注,从而添加客户备注。所以跟踪参考将始终是最后一项。
如何在客户订单历史记录中显示最后的订单备注?似乎不存在用于在客户端显示订单备注的插件。
理想结果:
我编写了一些代码,用于在基于产品类别的产品详细信息页面上显示自定义缺货消息。
function custom_backorder_message( $text, $product ){
if ( $product->managing_stock() && $product->is_on_backorder( 1 ) ) {
if( has_term( 'bridal-line', 'product_cat' ) ) {
$text = __( 'Your piece will be handcrafted for you. Upon order we will manufacture your piece of eternity. Sadly, we can not give you a timeline, due to Covid 19, but are expecting 5-7 weeks', 'text-domain' );
}else {
$text = __( 'This product is currently out of stock, but upon order we will handcraft your piece. …Run Code Online (Sandbox Code Playgroud) 我的联盟脚本跟踪下订单后的转化。它在动作挂钩内运行woocommerce_thankyou:
function affiliate_tracking_code( $order_id ) {
// get the order info for the script
?>
<script>
// affiliate script here
</script>
<?php
}
add_action( 'woocommerce_thankyou', 'affiliate_tracking_code', 10, 1 );
Run Code Online (Sandbox Code Playgroud)
如果订单失败或待处理,我不希望触发此脚本。只要成功的话。我在文档中找不到woocommerce_thankyou除了成功订单之外是否会触发操作挂钩。
如果确实如此,那么确保我的脚本仅跟踪成功订单而不跟踪失败订单的转化的最佳方法是什么?
我测试过的一种方法是将我的脚本包装在 if 和 check 中if ( $order->get_status() == 'processing' ) : // run the script,但是我不确定是否存在隐藏的漏洞。
我创建了一个名为“批发商”的新角色。该角色按预期发挥作用。
我还创建了一个名为“批发商价格”的自定义价格字段。它也按预期工作。
我检查用户角色,如果他们被分配为批发商,我会给他们定制产品价格(如果已填写)。我一切都在工作,除了我无法弄清楚最后的部分。如何提取当前产品 ID、获取批发价格并分配它。我的functions.php代码如下:
/* Custom user roles */
add_role( 'wholesaler', 'Wholesaler', get_role( 'customer' )->capabilities );
add_action( 'woocommerce_product_options_pricing', 'action_woocommerce_product_options_pricing', 10, 0 );
/* Add custom wholesaler price field to general page */
function action_woocommerce_product_options_pricing() {
woocommerce_wp_text_input( array(
'id' => 'wholesaler_price',
'class' => 'wc_input_price short',
'label' => __( 'Wholesaler price', 'woocommerce' ) . ' (' . get_woocommerce_currency_symbol() . ')',
) );
}
// Save Fields
function action_woocommerce_admin_process_product_object( $product ) {
if( isset($_POST['wholesaler_price']) ) {
$product->update_meta_data( 'wholesaler_price', sanitize_text_field( $_POST[ 'wholesaler_price'] ) ); …Run Code Online (Sandbox Code Playgroud) 使用添加在 WooCommerce 4+ 答案代码中发送电子邮件通知的新订单状态,我已经能够收到一个自定义状态的电子邮件通知,但无法了解如何发送电子邮件通知两种自定义状态。
请参阅下面的示例代码和我尝试过的多个自定义状态电子邮件通知的代码。我还包含了完整的代码,它显示了创建多个状态的整个过程。
希望对这个快速修复有所帮助!
另外,至于电子邮件正文 - 是否有可能通过此代码更改处理订单内容,而无需创建新的电子邮件模板?
正在运行 - 单个自定义状态电子邮件通知“已发货”
add_filter( 'woocommerce_email_actions', 'filter_woocommerce_email_actions' );
function filter_woocommerce_email_actions( $actions ){
$actions[] = 'woocommerce_order_status_wc-shipped';
return $actions;
}
// Send Customer Processing Order email notification when order status get changed from "tree" to "processing"
add_action('woocommerce_order_status_changed', 'shipped_status_custom_notification', 10, 4);
function shipped_status_custom_notification( $order_id, $from_status, $to_status, $order ) {
if( 'shipped' === $to_status ) {
// The email notification type
$email_key = 'WC_Email_Customer_Processing_Order';
// Get specific WC_emails object
$email_obj = WC()->mailer()->get_emails()[$email_key];
// Sending …Run Code Online (Sandbox Code Playgroud) hook-woocommerce ×10
woocommerce ×10
wordpress ×10
php ×9
orders ×3
checkout ×2
payment ×1
price ×1
product ×1
woothemes ×1