Banner Logo

Be a part of the family: Connect, Receive Support,
Contribute, and Reap Abundant Rewards!

Display message if default title is assigned

WCMp Advanced Frontend Manager

Resolved
Viewing 11 reply threads
  • Author
    Posts
    • #138011
      Tim Kerremans
      Participant

      Hi there,

      So I found the code below to check if product title is set and image has been attached. However, when vendors create a product, a default title is assigned. This default title is always ‘Product’. How can I check if default title is set and display this error message if the default title has not been changed?

      /**
      **required some wcmp product field
      **/
      add_action( ‘wcmp_before_post_update’, ‘required_wcmp_product_field’ );
      function required_wcmp_product_field(){
      $required_feature_image = isset( $_POST[‘featured_img’] ) ? $_POST[‘featured_img’] : ”;
      $required_post_title = isset( $_POST[‘post_title’] ) ? $_POST[‘post_title’] : ”;

      if(!$required_feature_image || !$required_post_title ){
      wc_add_notice( __(‘Please ensure you have added a Product Title, Image, ‘dc-woocommerce-multi-vendor’), ‘error’ );
      wp_redirect( apply_filters( ‘wcmp_vendor_save_product_redirect_url’, wcmp_get_vendor_dashboard_endpoint_url( get_wcmp_vendor_settings( ‘wcmp_edit_product_endpoint’, ‘vendor’, ‘general’, ‘edit-product’ ), $_POST[‘post_ID’] ) ) );
      exit;
      }
      }

    • #138014

      Hi @Tim Kerremans, as per WooCommerce flow, a product without a title can’t be saved. That is why the default name is added.

      Now for your requirement, please use this default code :

      /**
      **required some wcmp product field 
      **/
      add_action( 'wcmp_before_post_update', 'required_wcmp_product_field' );
      function required_wcmp_product_field(){
          $required_feature_image = isset( $_POST['featured_img'] ) ? $_POST['featured_img'] : '';
          $required_post_title = isset( $_POST['post_title'] ) ? $_POST['post_title'] : '';
          
          if(!$required_feature_image || !$required_post_title ){
              wc_add_notice( __('Please ensure you have added a Product Title, Image', 'dc-woocommerce-multi-vendor'), 'error' );
              wp_redirect( apply_filters( 'wcmp_vendor_save_product_redirect_url', wcmp_get_vendor_dashboard_endpoint_url( get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' ), $_POST['post_ID'] ) ) );
              exit;
          }
      }
      Copy
    • #138026
      Tim Kerremans
      Participant

      Hi,

      The code you gave is the exact same code as I gave in my first message.
      I understand that there must be a default title, I just want to obligate my vendors to change this default title.

      Kind regards,

    • #138041

      Tim you have missed one “`” after Image.

      Also, the vendor can edit the name from here : https://prnt.sc/5HJzLwloHkPw

    • #138043
      Tim Kerremans
      Participant

      It seems like you didn’t understand what I’m trying to do.

      This is the flow:
      Step 1) Product gets created -> default title ‘Product’ is assigned
      Step 2) Vendor edits product but forgets to edit the title and attach an image
      Step 3) Vendor tries to submit the product
      Step 4) Vendor gets message saying that he must attach image and change the default title before he can publish the product

      The code i shared in this forum message was just a code I copy-pasted from another forum topic of this website for you to have a starting point. This code checks if title and image is set to the product.

      What I’m asking: I need to check if the title equals ‘Product’, if so, the vendor must receive this error message as he cannot submit product with default title. If not, the vendor can publish the product as usual

    • #138096

      Hi,
      Kindly add below code to your function.php and check

      /**
      **required some wcmp product field 
      **/
      add_action( 'wcmp_before_post_update', 'required_wcmp_product_field' );
      function required_wcmp_product_field(){
          $required_post_title = isset( $_POST['post_title'] ) ? $_POST['post_title'] : '';    
          if ($required_post_title == 'Product' || empty($required_post_title)) {
              wc_add_notice( __('You cannot submit product with default title.', 'dc-woocommerce-multi-vendor'), 'error' );
              wp_redirect( apply_filters( 'wcmp_vendor_save_product_redirect_url', wcmp_get_vendor_dashboard_endpoint_url( get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' ), $_POST['post_ID'] ) ) );
              exit;
          }
      }
      Copy

      regards,

    • #138097
      Tim Kerremans
      Participant

      This works perfectly, thanks!

    • #138107

      @Tim Kerremans, the flow you are looking for requires further custom code.

      So it might take some time for our team to provide this code. In the meantime, please do share a temporary admin, FTP access so we can check.
      While sharing the access don’t forget to mark the response as private.

    • #138108
      Tim Kerremans
      Participant
      This reply has been marked as private.
    • #138172
      This reply has been marked as private.
    • #138173
      Tim Kerremans
      Participant

      Yes, ticket is resolved 🙂

    • #138188
      This reply has been marked as private.
Viewing 11 reply threads

The topic ‘Display message if default title is assigned’ is closed to new replies.