WCMp Advanced Frontend Manager
-
AuthorPosts
-
-
June 17, 2022 at 2:38 AM #138011Tim KerremansParticipant
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;
}
} -
June 17, 2022 at 12:27 PM #138014NerdySupportExpert MoumitaKeymaster
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 -
June 17, 2022 at 1:36 PM #138026Tim KerremansParticipant
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,
-
June 17, 2022 at 7:06 PM #138041NerdySupportExpert MoumitaKeymaster
Tim you have missed one “`” after Image.
Also, the vendor can edit the name from here : https://prnt.sc/5HJzLwloHkPw
-
June 17, 2022 at 7:13 PM #138043Tim KerremansParticipant
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 productThe 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
-
June 20, 2022 at 6:28 PM #138096MVX Support NinjaKeymaster
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; } }
Copyregards,
-
June 20, 2022 at 6:57 PM #138097Tim KerremansParticipant
This works perfectly, thanks!
-
June 20, 2022 at 8:38 PM #138107MVX Support NinjaKeymaster
@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. -
June 20, 2022 at 8:50 PM #138108Tim KerremansParticipantThis reply has been marked as private.
-
June 22, 2022 at 3:47 PM #138172NerdySupportExpert MoumitaKeymasterThis reply has been marked as private.
-
June 22, 2022 at 3:48 PM #138173Tim KerremansParticipant
Yes, ticket is resolved 🙂
-
June 22, 2022 at 7:17 PM #138188NerdySupportExpert MoumitaKeymasterThis reply has been marked as private.
-
-
AuthorPosts
The topic ‘Display message if default title is assigned’ is closed to new replies.