-1

I added custom product_type_option like this

enter image description here

by filter product_type_option hook like this

function rpf_add_wild_card_product_type_option($type_options) {
    $checked = 'no';
    $type_options['wild_card'] = array(
        'id'            => '_wild_card',
        'wrapper_class' => 'show_if_simple',
        'label'         => __('Wild Card', 'woocommerce'),
        'description'   => __('Please check if this product is wild card', 'woocommerce'),
        'default'           => $checked,
    );
    return $type_options;
}
add_filter('product_type_option', 'rpf_add_wild_card_product_type_option', 100, 1);

But, WooCommerce never save Wild Card Field!

I want WooCommerce treat my wild card product type option like Virtual,Downloadable Field.

What should I do in this case?

  • please edit your question to put the code directly instead of a picture. – mmm Jan 28 '18 at 11:11
4

Your code only creates the checkbox, you need also to save the value like that

add_filter("product_type_options", function ($product_type_options) {

    $product_type_options["wildcard"] = [
        "id"            => "_wildcard",
        "wrapper_class" => "show_if_simple",
        "label"         => "Wildcard",
        "description"   => "Description",
        "default"       => "no",
    ];

    return $product_type_options;

});


add_action("save_post_product", function ($post_ID, $product, $update) {

    update_post_meta(
          $product->ID
        , "_wildcard"
        , isset($_POST["_wildcard"]) ? "yes" : "no"
    );

}, 10, 3);
  • I created bookable check box but when i check it and update it and edit again its not checked although the data is saved in database but i want to show a check-mark if it is checked or not. any help please. – DHL17 Mar 13 '18 at 11:14
  • I find it its default => 'yes'. any ways your answer helped me thanks. – DHL17 Mar 13 '18 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.