I want to limit the aspects of the product a vendor can edit on the Edit product. I basically only want to allow them to edit the product description, which for me is stored in some ACF fields.
I successfully hid the Product data session (by deleting that section in the edit-products.php I copied into my theme). Similarly, I tried hiding the product image and title fields, but when I update the product they are simply deleted (product reverts title to "undefined" and featured image is gone). Seems it basically saves the values as null instead of ignoring them.
You could argue a simple solution would be to hide the fields using CSS, but I'd rather not allow people with some know-how to unhide it and change it.
1: What is your purposed method of hiding/disabling the product image and product title fields on the Edit Products page?
2: Do you have any suggestions on how to save ACF data with the "Update Product" trigger? I've tried with my limited understanding – seems the actual saving of data happens in the public.js around line 630? I tried including versions of this line, but without any results: do_action( 'acf/save_post', $post_id ); I am able to save data using the "built in" update-button that is included with ACF, but ideally I would have it be part of action with "Update Product", to avoid confusion with two different submit buttons.
It seems its currently not possible to override the public.js by placing it in the theme/marketking folder? (also tried creating a /assets and assets/js inside the marketking folder without luck.
P.S. I currently add the acf_form in edit-products.php with this code: while ( have_posts() ) : the_post(); acf_form(array( 'fields' => array('quote', 'description' ), 'form' => false, )); endwhile;
My next challenge is trying to fix the display of upload fields (like the ACF field types of 'gallery' and 'file upload'). Right now they only lead to "#", not triggering the uploaders that the normal WYSIWYG and Media Uploader should. You don't happen to know of something potentially blocking this default behaviour? Otherwise I'll keep looking in the ACF forums ;)
Normally what would happen is that ACF would probably use specific styles (.css files) and scripts to enable the uploader functionalities.
MarketKing completely disconnects the dashboard from default styles and scripts - we did this because we want to preserve the specific design of the dashboard, regardless of theme and other plugins, and prevent conflict.
To do this, we are specifically telling the dashboard which scripts and which styles to allow.
I believe you can fix this by adding the ACF styles and scripts to the MarketKing dashboard.
I would suggest trying the following:
Copy the marketking-dashboard-login.php file (from marketking core / public / dashboard) to your child theme, and edit it there.
In that file you will find lines of code that start with:
$wp_styles->queue =
$wp_scripts->queue =
Those are the lines responsible for setting which scripts and styles are allowed. You could add the acf ones there directly, or maybe before doing anything else, try to delete those lines of code to see if that works to enable ACF.
Where you see lines like this one $wp_styles->queue = array('marketking_dashboard','media-views','imgareaselect', 'wc-country-select', 'select2', 'selectWoo', 'simplebar');
You would need to edit that array to include the ACF styles / scripts.
I don't know exactly what they use. Sometimes you can find it by viewing the page source code and searching for '-css' and '-js' and you may be able to find something like 'acf-css', 'acf-js'.
I hope that makes sense - I don't know if I'm very good at explaining these things. If you have any questions, please let me know,
Took me a while to be able to test out, but haven't had any luck. I have tried commenting out both the $wp_styles and $wp_scripts lines, even the wp_print_styles and wp_print_scripts add_actions – None of it makes any difference. Everything looks exactly the same as before (no WYSIWYG editor or upload areas loading, but also nothing missing / visually different at all).
I have tried manually adding all the scripts and styles – and see that they do load, but again, no difference made.
Strange, right?
Could there be some other place the scripts are being blocked or made inactive?
If I put the form elements on any page or template outside of Marketplace, they appear as expected, so something must be interfering.
To reproduce the conditions: In the edit-product.php I have added a div:
<div class="col-xxl-6 col-md-6"> <div id="postexcerpt" class="postbox col-xxl-6"> <h4>Quote</h4> <?php while ( have_posts() ) : the_post(); ?> <?php acf_form(array( 'fields' => array('quote', 'description', 'author', 'testfield', 'media-slider', 'video'), 'form' => false, 'post_id' => $productid, 'uploader' => 'basic' )); ?> <?php endwhile; ?> </div> </div> The fields in the div refer to field-names in ACF. In addition I have added <?php acf_form_head(); ?> at the top of the file to allow it to save properly.
The saving of data works as described earlier, but the UI is not loading, which currently blocks me from allowing anyone in, since I don't want to present html formatting like <em>-tags inside a textarea.
Would really appreciate any help to move forward on this!
Would you be able to share a backend login to the site (or a staging site) you're working on, so I could look into this directly?
I'm not very experienced with ACF, and even if I replicated the issue on a local site, it would be of no help if it worked for me locally but not on your actual site - so it would be best if I could just work on the actual site directly.
If I put the form elements on any page or template outside of Marketplace, they appear as expected, so something must be interfering.
So it's working if loaded outside the vendor dashboard? I think there's just some script or style that's not working for some reason. I can try to identify it.
It's the strangest thing. Initially it seemed to work, but for some reason it stopped. I have tried reverting the server back to the point right after you fixed it, which unfortunately didn't help.
You provided core-1429 in another ticket for me – I am assuming this has the filters you added here? Is there anything other than the code snippet that was modified? Right now, it doesn't seem to load those filters (the scripts aren't loading). I see you add two filters via code snippet. (marketking_js_queue and marketking_css_queue) Do they need to be referred to somewhere in the plugin, theme or edit-product page? Or should it simply know where to load those?
I am super happy with the support and the product. You had my issue fixed and then I somehow lost it. Would you please be able to have another look?
P.S. I assume you were the one on wordpress.org forum to also help me figure out the "On hold" behaviour (that was simply hiding in plain sight under composite orders). Really grateful for all your help!
( Oh, I know which thread you mean on wordpress.org, yeah, that was me as well, we have an alert for specific terms like 'marketking'. Though I saw 'wang' in the username and I thought that must be one of our Asian customers )
Super! We're back :) The last thing on this to fix would be to stop the beforeunload that now fires (browser warning). I am assuming that happens because we no longer use the default save method? Have tried adding these scripts:
I want to limit the aspects of the product a vendor can edit on the Edit product.
I basically only want to allow them to edit the product description, which for me is stored in some ACF fields.
I successfully hid the Product data session (by deleting that section in the edit-products.php I copied into my theme). Similarly, I tried hiding the product image and title fields, but when I update the product they are simply deleted (product reverts title to "undefined" and featured image is gone). Seems it basically saves the values as null instead of ignoring them.
You could argue a simple solution would be to hide the fields using CSS, but I'd rather not allow people with some know-how to unhide it and change it.
1: What is your purposed method of hiding/disabling the product image and product title fields on the Edit Products page?
2: Do you have any suggestions on how to save ACF data with the "Update Product" trigger? I've tried with my limited understanding – seems the actual saving of data happens in the public.js around line 630?
I tried including versions of this line, but without any results:
do_action( 'acf/save_post', $post_id );
I am able to save data using the "built in" update-button that is included with ACF, but ideally I would have it be part of action with "Update Product", to avoid confusion with two different submit buttons.
It seems its currently not possible to override the public.js by placing it in the theme/marketking folder? (also tried creating a /assets and assets/js inside the marketking folder without luck.
P.S. I currently add the acf_form in edit-products.php with this code:
while ( have_posts() ) : the_post();
acf_form(array(
'fields' => array('quote', 'description' ),
'form' => false, ));
endwhile;
Hi there,
The function that saves the product is in class-marketking-core.php and is named marketkingsaveproduct()
I've now added a filter there, that will allow you to disable the standard product save function, so you can add your own code there.
To do this, first update the MarketKing Core plugin to 1.3.32 or higher, and then add this PHP code snippet to your site:
With this added, product data like images, descriptions, etc will no longer be saved.
Now you can add your own function to save products as follows:
The above is just an example - I'm not really sure how ACF saves items so I'm not sure if this will work or not - it might though
Indeed it is not possible to replace public.js , at least not yet.
Let me know if the above works for you,
Thank you for this! It seems to work well with saving the ACF fields!
I only had an issue with the redirects going to /edit-products/update=success – which lost the relation to the product id.
I was able to fix this by adding an action to the 'acf/save_post' like this:
function my_acf_save_post( $product_id ) { echo $product_id;
}
add_action('acf/save_post', 'my_acf_save_post', 20);
My next challenge is trying to fix the display of upload fields (like the ACF field types of 'gallery' and 'file upload'). Right now they only lead to "#", not triggering the uploaders that the normal WYSIWYG and Media Uploader should. You don't happen to know of something potentially blocking this default behaviour? Otherwise I'll keep looking in the ACF forums ;)
Thanks again!
How those fields are displayed now
Normally what would happen is that ACF would probably use specific styles (.css files) and scripts to enable the uploader functionalities.
MarketKing completely disconnects the dashboard from default styles and scripts - we did this because we want to preserve the specific design of the dashboard, regardless of theme and other plugins, and prevent conflict.
To do this, we are specifically telling the dashboard which scripts and which styles to allow.
I believe you can fix this by adding the ACF styles and scripts to the MarketKing dashboard.
I would suggest trying the following:
Copy the marketking-dashboard-login.php file (from marketking core / public / dashboard) to your child theme, and edit it there.
In that file you will find lines of code that start with:
$wp_styles->queue =
$wp_scripts->queue =
Those are the lines responsible for setting which scripts and styles are allowed. You could add the acf ones there directly, or maybe before doing anything else, try to delete those lines of code to see if that works to enable ACF.
Where you see lines like this one $wp_styles->queue = array('marketking_dashboard','media-views','imgareaselect', 'wc-country-select', 'select2', 'selectWoo', 'simplebar');
You would need to edit that array to include the ACF styles / scripts.
I don't know exactly what they use. Sometimes you can find it by viewing the page source code and searching for '-css' and '-js' and you may be able to find something like 'acf-css', 'acf-js'.
I hope that makes sense - I don't know if I'm very good at explaining these things. If you have any questions, please let me know,
Kind regards,
Stefan
Took me a while to be able to test out, but haven't had any luck.
I have tried commenting out both the $wp_styles and $wp_scripts lines, even the wp_print_styles and wp_print_scripts add_actions – None of it makes any difference. Everything looks exactly the same as before (no WYSIWYG editor or upload areas loading, but also nothing missing / visually different at all).
I have tried manually adding all the scripts and styles – and see that they do load, but again, no difference made.
Strange, right?
Could there be some other place the scripts are being blocked or made inactive?
If I put the form elements on any page or template outside of Marketplace, they appear as expected, so something must be interfering.
To reproduce the conditions:
In the edit-product.php I have added a div:
<div class="col-xxl-6 col-md-6"> <div id="postexcerpt" class="postbox col-xxl-6"> <h4>Quote</h4> <?php while ( have_posts() ) : the_post(); ?> <?php acf_form(array( 'fields' => array('quote', 'description', 'author', 'testfield', 'media-slider', 'video'), 'form' => false, 'post_id' => $productid, 'uploader' => 'basic' )); ?> <?php endwhile; ?> </div> </div>
The fields in the div refer to field-names in ACF.
In addition I have added <?php acf_form_head(); ?> at the top of the file to allow it to save properly.
The saving of data works as described earlier, but the UI is not loading, which currently blocks me from allowing anyone in, since I don't want to present html formatting like <em>-tags inside a textarea.
Would really appreciate any help to move forward on this!
Just bumping this request!
Hi again,
Would you be able to share a backend login to the site (or a staging site) you're working on, so I could look into this directly?
I'm not very experienced with ACF, and even if I replicated the issue on a local site, it would be of no help if it worked for me locally but not on your actual site - so it would be best if I could just work on the actual site directly.
If I put the form elements on any page or template outside of Marketplace, they appear as expected, so something must be interfering.
So it's working if loaded outside the vendor dashboard? I think there's just some script or style that's not working for some reason. I can try to identify it.
Kind regards,
Stefan
I was able to look a bit into this now.
Here's what I've done so far for reference:
- I added some new filters in marketking-dashboard-login.php (these will exist in the next plugin updates)
- I added this code snippet here: https://sandbox.pokket.no/wp-admin/admin.php?page=edit-snippet&id=21&result=updated
We have some progress and I think the text editor is working fine now:
It would help if you can check and let me know where we're at right now. What is still not working if anything?
It's the strangest thing. Initially it seemed to work, but for some reason it stopped. I have tried reverting the server back to the point right after you fixed it, which unfortunately didn't help.
You provided core-1429 in another ticket for me – I am assuming this has the filters you added here? Is there anything other than the code snippet that was modified? Right now, it doesn't seem to load those filters (the scripts aren't loading). I see you add two filters via code snippet. (marketking_js_queue and marketking_css_queue) Do they need to be referred to somewhere in the plugin, theme or edit-product page? Or should it simply know where to load those?
I am super happy with the support and the product. You had my issue fixed and then I somehow lost it. Would you please be able to have another look?
P.S. I assume you were the one on wordpress.org forum to also help me figure out the "On hold" behaviour (that was simply hiding in plain sight under composite orders). Really grateful for all your help!
I think the issue is that core-1429 did not have those filters yet (I probably added them after that version).
I checked now and added those filters in your local version and it seems to be working again. Easy fix!
I also attached a newer core version in case you will need it in the future.
I'm glad if you're happy with the plugin and thank you for the kind words! If you have some spare time, it's a great help if you can leave a rating on wp.org: https://wordpress.org/plugins/marketking-multivendor-marketplace-for-woocommerce/#reviews (helps boost the plugin's visibility).
( Oh, I know which thread you mean on wordpress.org, yeah, that was me as well, we have an alert for specific terms like 'marketking'. Though I saw 'wang' in the username and I thought that must be one of our Asian customers )
Kind regards,
Stefan
Super! We're back :)
The last thing on this to fix would be to stop the beforeunload that now fires (browser warning). I am assuming that happens because we no longer use the default save method?
Have tried adding these scripts:
$('form').submit(function() {
$(window).unbind('beforeunload');
});
or
jQuery(window).off('beforeunload');
But no luck yet. We're so close now! Any suggestions?
P.S. I gave you reviews on both wordpress and codecanyon :)
Thank you so much for your kind reviews!
I've made an update to the MarketKing Core plugin on your site and I added jQuery(window).off('beforeunload'); just before the page is reloaded.
Seems to be working in my tests. Let me know if I can help with anything else!