I am trying to build a function for woocommerce and want to save these data to my wp_option.
function custom_before_price() {
$args = array(
'id' => 'custom_before_price_table1',
'label' => __( 'Before Price', 'cbp1' ),
'class' => 'cbp-custom-field',
'desc_tip' => true,
'description' => __( 'Enter the text before price.', 'cbpdes' ),
);
woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_product_options_general_product_data', 'custom_before_price' );
3
Answers
You should use add_option().something like this
Saving the values to the wp_options table is not a normal WooCommerce behavior. WooCommerce saves product meta in wp_postmeta. There are a lot of possible downsides to storing data about specific products in wp_options. In particular, if you need to return data to the product admin editor from wp_options, you will need to labor on a method for that, as WooCommerce looks to wp_postmeta for custom meta.
The following set of functions will create your custom input and save the value when the product is updated via WP Admin.