Create dynamic variable that contains vendor name for email subject

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WC Marketplace Create dynamic variable that contains vendor name for email subject

Viewing 6 reply threads
  • Author
    Posts
    • #50701
      andreasenglowski
      Participant

      Hi,

      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

    • #50719
      andreasenglowski
      Participant

      Did 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?

    • #50732
      WCFM Forum
      Keymaster

      Hi,

      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

    • #50740
      andreasenglowski
      Participant

      Hi,

      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,
      andi

      Attachments:
      You must be logged in to view attached files.
    • #50761
      andreasenglowski
      Participant

      Hey, 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 🙂

    • #50762
      WCFM Forum
      Keymaster

      Hi,

      $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

    • #50764
      WCFM Forum
      Keymaster

      Hi,

      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

Viewing 6 reply threads
  • The topic ‘Create dynamic variable that contains vendor name for email subject’ is closed to new replies.