简体   繁体   English

使用供应商商店名称(Dokan)自定义 WooCommerce 中的 email 主题

[英]Customize email subject in WooCommerce with vendor store-name (Dokan)

We found this question https://wordpress.stackexchange.com/questions/320924/woocommerce-order-processing-email-subject-not-changing and it's working fine.我们发现了这个问题https://wordpress.stackexchange.com/questions/320924/woocommerce-order-processing-email-subject-not-change并且工作正常。 We now want to extend this by display the vendor on a order in the order completed mail.我们现在想通过在订单完成邮件中显示订单上的供应商来扩展它。

But we are not able to output the vendor store name.但是我们不能 output 供应商商店名称。

Is there a obvious error in our code?我们的代码有明显的错误吗?

add_filter( 'woocommerce_email_subject_customer_completed_order', add_filter('woocommerce_email_subject_customer_completed_order',

'change_completed_email_subject', 1, 2 );
function change_completed_email_subject( $subject, $order ) {
global $woocommerce;

// Order ID 
$order->get_items();
     
// Author id
$author_id = $product->post->post_author;
        
// Shopname
$vendor = dokan()->vendor->get( $author_id );
$shop_name = $vendor->get_shop_name();

// Blogname
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

// Output subject
$subject = sprintf( '%s, Deine %s Bestellung (#%s) wurde versendet! Vendor: %s', $order->billing_first_name, $blogname, $order->get_order_number(), $shop_name );
return $subject;
}

Update:更新:

I already tried to get the name via $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();我已经尝试通过$shop_name = dokan()->vendor->get( $author_id )->get_shop_name(); but no success.但没有成功。

  • The use of global $woocommerce is not necessary没有必要使用 global $woocommerce
  • You use $order->get_items();你使用$order->get_items(); , but don't do anything with it ,但不要对它做任何事情
  • $product is not defined $product未定义
  • Use $order->get_billing_first_name() VS $order->billing_first_name使用$order->get_billing_first_name() VS $order->billing_first_name

So you get:所以你得到:

function filter_woocommerce_email_subject_customer_completed_order( $subject, $order ) {
    // Empty array
    $shop_names = array();
    
    // Loop through order items
    foreach ( $order->get_items() as $item ) {
        // Get product object
        $product = $item->get_product();

        // Author id
        $author_id = $product->post->post_author;
        
        // Shopname
        $vendor = dokan()->vendor->get( $author_id );
        $shop_name = $vendor->get_shop_name();
        
        // OR JUST USE THIS FOR SHOPNAME
        // Shop name
        // $shop_name = dokan()->vendor->get( $author_id )->get_shop_name();
        
        // NOT in array
        if ( ! in_array( $shop_name, $shop_names ) ) {
            // Push to array
            $shop_names[] = $shop_name;
        }
    }

    // Blogname
    $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);

    // Set subject
    $subject = sprintf( __( '%s, Deine %s Bestellung (#%s) wurde versendet! Vendor: %s', 'woocommerce' ), $order->get_billing_first_name(), $blogname, $order->get_order_number(), implode( ', ', $shop_names ) );

    // Return
    return $subject;
}
add_filter( 'woocommerce_email_subject_customer_completed_order', 'filter_woocommerce_email_subject_customer_completed_order', 10, 2 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 WooCommerce 管理员订单预览上显示供应商商店名称 (Dokan) - Display vendor store-name (Dokan) on WooCommerce admin order preview 将 Dokan 供应商送货地址分配给 Woocommerce 中的商店地址 - Assign Dokan vendor shipping address to store address in Woocommerce 在 Woocommerce 单个产品页面上显示 dokan 供应商名称 - Display dokan vendor name on Woocommerce single product pages 在 Woocommerce 单个产品页面上显示 Dokan 供应商名称和总销售额 - Display Dokan vendor name and total sales on Woocommerce single product pages 在 WooCommerce 产品目录上显示 Dokan 供应商国家 - Show Dokan vendor country on WooCommerce product catalog 添加默认 WooCommerce 运输到 Dokan 供应商仪表板 - Adding Default WooCommerce Shipping to Dokan Vendor Dashboard 如何通过添加供应商名称作为后缀来更改 WooCommerce 订单 ID(Dokan 插件) - How to change the WooCommerce order id by adding the vendor name as a suffix (Dokan plugin) 将产品名称添加到 WooCommerce 中的电子邮件主题 - Add the product name to the email subject in WooCommerce 从供应商面板更新 WooCommerce Dokan 插件中的产品有什么钩子? - What hook for updating product in WooCommerce Dokan plugin from vendor panel? 使用 Dokan 插件时按供应商对 WooCommerce 购物车物品进行排序 - Sort WooCommerce cart items by vendor when using Dokan plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM