jeudi 29 décembre 2016

Add condition to Woocommerce plugin for default setting

I'm trying to add a condition to a Woocommerce plugin to limit the default enabling function to only be for certain product categories. I've got the functions to return the category names working, but I'm not sure how to add it into this plugin.

The constructor uses this line to set it:

$this->gift_wrap_enabled         = get_option( 'product_gift_wrap_enabled' ) == 'yes' ? true : false;

Then it gets the option from the settings:

add_option( 'product_gift_wrap_enabled', 'no' )

$this->settings = array(
        array(
            'name'      => __( 'Gift Wrapping Enabled by Default?', 'woocommerce-product-gift-wrap' ),
            'desc'      => __( 'Enable this to allow gift wrapping for products by default.', 'woocommerce-product-gift-wrap' ),
            'id'        => 'product_gift_wrap_enabled',
            'type'      => 'checkbox',
        ),

This code shows what I was trying to do.

function parent_cat_enable() {
    global $post;
    if (all_cat_classes($post)) === 'parent-category'){
    $this->gift_wrap_enabled = true;
    }
    return $this->gift_wrap_enabled;
}

Any help would be greatly appreciated! Thanks.

Aucun commentaire:

Enregistrer un commentaire