סניפט קוד להוספת שדה בתוך עמוד מוצר וריאציה או מוצר רגיל בטאב של ווקומרס INVENTORY
במקרה ורוצים להוסיף שדה לINVENTORY יש לקרוא לאקשן woocommerce_product_options_inventory_product_data
במקרה ורוצים להוסיף שדה בGENERAL אך יש לשים לב שGENERAL קיים רק בעמוד מוצר רגיל ולא וריאציה יש לקרוא לאקשן woocommerce_product_options_general_product_data
// add alert field to product page add_action( 'woocommerce_product_options_inventory_product_data', 'gs_create_custom_field' ); function gs_create_custom_field() { $args = array( 'id' => 'custom_text_field_title', 'label' => __( 'Add Extra Sign Image', 'gsolution' ), 'class' => 'gs-custom-field', 'desc_tip' => true, 'description' => __( 'Add Extra Sign', 'gsolution' ), ); woocommerce_wp_checkbox( $args ); }
לשמירת השדה יש להוסיף את הסניפט הבא
// save field add_action( 'woocommerce_process_product_meta', 'gs_save_custom_field' ); function gs_save_custom_field( $post_id ) { $product = wc_get_product( $post_id ); $title = isset( $_POST['custom_text_field_title'] ) ? $_POST['custom_text_field_title'] : ''; $product->update_meta_data( 'custom_text_field_title', sanitize_text_field( $title ) ); $product->save(); }
לשליפת השדה בעמוד מוצר
add_action( 'woocommerce_before_variations_form', 'gs_add_alert' ); function gs_add_alert(){ global $post; $field = get_post_meta( $post->ID, 'custom_text_field_title', $single = false ); if($field['0'] == 'yes'): echo '<div class="extra-sign-img"><img src="" alt="sign"/><a href="/about-us/" class="more-details-sign">לפרטים נוספים</a></div>'; endif; //var_dump($field); //echo '<div class="product-variations-alert"></div>'; }
ביטול שדות והשימוש במק"ט או SKU בכל ווקומרס
//add_filter( 'wc_product_sku_enabled', '__return_false' );