php - Wordpress - Woocommerce -


I found some custom field tutorials for WP and Woocommerce. So I played little with that. It all works well, but I tried to optimize the part that the checkbox saves prices while checking, and unfortunately I am not able to fulfill it. This is what I am trying to do, the code snippet in functions.php:

  // Custom field for the price label / display field add_action ('woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields') ; // Save field add_action ('woocommerce_process_product_meta', 'woo_add_custom_general_fields_save'); Function woo_add_custom_general_fields () {global $ woocommerce, $ post; // checkbox woocommerce_wp_checkbox (array ('id' = & gt; '_primer', 'wrapper_class' = & gt; '', 'label' = & gt; __ ('primer', 'woocommerce'), 'description' = & Gt; __ ('Check Me!', 'Woocommerce'))); } Function woo_add_custom_general_fields_save ($ post_id) {// checkbox_1 $ woocommerce_checkbox_primer = isset ($ _POST ['_ primer'])? 'Yes' : ''; Update_post_meta ($ post_id, '_primer', $ woocommerce_checkbox_primer); }   

... and then a single product. This peace of code in FP

  & lt; Span & gt; & Lt ;? Php echo get_post_meta (get_the_ID (), '_primer', true); ? & Gt; & Lt; / Span & gt;   

So when it is implemented, I have a big "yes" on a single product page, but I want to get the image instead of "yes", so if the checkbox shows To check the image on a single product page, and to save that selection to the database. I hope I was quite clear, and thanks in advance

I'm not 100% sure that I I understand, but it seemed as if you wanted to show the image conditionally if the checkbox was right in the backend

  if ('yes' == get_post_meta (get_the_ID), '_primer' , This is the truth)) {? & Gt; & Lt; Img src = "your-image.png" / & gt; & Lt ;? Php}    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -