Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Marketplace › Create dynamic variable that contains vendor name for email subject
- This topic has 6 replies, 2 voices, and was last updated 5 years, 12 months ago by
WCFM Forum.
- AuthorPosts
- March 1, 2019 at 8:41 am #50701
andreasenglowski
ParticipantHi,
is there a way to create a dynamic variable that contains the vendor name to use in emails?
For example:
-> New order email for customer:
Email subject: [{site_title}] Thanks for ordering with {vendor}Thanks in advance,
Andi - March 1, 2019 at 10:28 am #50719
andreasenglowski
ParticipantDid find that code:
add_filter( ‘woocommerce_email_format_string’ , ‘filter_email_format_string’, 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
‘{vendor}’ => CODE GOES HERE // <=== HERE
);// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}Where i just need to get the vendor name from the order object. is that possbile?
- March 1, 2019 at 11:28 am #50732
WCFM Forum
MemberHi,
Sorry, there is nothing like this.
Actually, how this is not possible.
Which vendor name will be added here? Depending upon which condition?
Thank You
- March 1, 2019 at 12:19 pm #50740
andreasenglowski
ParticipantHi,
the vendor name should be displayed depending on the order (so it should be the name of the vendor who is selling the product in that order).
Eg: customer purchsases one product ‚myProduct‘ from vendor ‚myVendor‘.
E-mail should say: thanks for ordering with myVendor.But there must be some way to get vendor information from WCOrder object, cause the vendor info (vendor store name plus url) is added to order confirmation email inside the table with order details in product info (see screenshot).
What about
‚$WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product()‘?
can i get vendor id from order with that function?thanks,
andiAttachments:
You must be logged in to view attached files. - March 1, 2019 at 2:25 pm #50761
andreasenglowski
ParticipantHey, i got it working 🙂
Heres my code:
add_filter( ‘woocommerce_email_format_string’ , ‘filter_email_format_string’, 20, 2 );
function filter_email_format_string( $string, $email ) {
// Get the instance of the WC_Order object
$order = $email->object;// Additional wanted placeholders in the array of find / relace pairs
$additional_placeholders = array(
‘{custom_one}’ => __(‘Mein Platzhalter’,’woocommerce’),
‘{vendor_link}’ => advi_get_vendor_link( $order ),
‘{vendor_name}’ => advi_get_vendor_name( $order ),
);// return the clean string with new replacements
return str_replace( array_keys( $additional_placeholders ), array_values( $additional_placeholders ), $string );
}function advi_get_vendor_name( $order ) {
global $WCFM, $WCFMmp;
$order_item = $order->get_items();foreach( $order_item as $product ) {
$productIDs[] = $product[‘product_id’];
$productID = $product[‘product_id’];
}
$vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $productID );
//This line return Link to Shop
//$shop_name = $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_by_vendor( $vendor_id );
$store_user = wcfmmp_get_store( $vendor_id );
$store_info = $store_user->get_shop_info();
//$store_name = isset( $store_info[‘store_name’] ) ? esc_html( $store_info[‘store_name’] ) : __( ‘N/A’, ‘wc-multivendor-marketplace’ );
$store_name = $store_info[‘store_name’];//return $productIDs[0];
return $store_name;
}Thanks 🙂
- March 1, 2019 at 2:26 pm #50762
WCFM Forum
MemberHi,
$WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product()‘?
can i get vendor id from order with that function?– No, I already told you – Products are associated with vendors but not Orders.
Order is not a single entity. One order may contain many products from different vendors.
Additional it has Shipping elements, tax, coupon and many other things …Thank You
- March 1, 2019 at 2:34 pm #50764
WCFM Forum
MemberHi,
This code will partially work –
foreach( $order_item as $product ) { $productIDs[] = $product[‘product_id’]; $productID = $product[‘product_id’]; } $vendor_id = $WCFM->wcfm_vendor_support->wcfm_get_vendor_id_from_product( $productID );
If one order contains only one vendor’s products then it will work.
But if order has different products from different vendors then it will return only last item’s vendor name.
Thank You
- AuthorPosts
- The topic ‘Create dynamic variable that contains vendor name for email subject’ is closed to new replies.