#StackBounty: #woocommerce #shortcode #child-theme Hide children categories from a WPBakery Widget

Bounty: 50

My theme comes with an addon plugin that include some visual composer element.

They display the products on my homepage, with categories filter. But I want to exclude subcategories products (children).

I already tried to add "include_children => false" in what I suppose to be the query, but it has no incidence on the code.

Here is the code of the bloc :

function supro_products( $atts, $content ) {

    $atts = shortcode_atts(

        array(

            'title'            => '',

            'subtitle'         => '',

            'style'            => '1',

            'limit'            => 6,

            'columns'          => 3,

            'm_columns'        => 1,

            'orderby'          => 'title',

            'order'            => 'ASC',

            'filter'           => 'category',

            'show_all_product' => '1',

            'all_product_text' => esc_html__( 'All Products', 'supro' ),

            'tabs'             => '',

            'category'         => '',

            'link'             => '',

            'load_more'        => false,

            'btn_style'        => 'border-bottom',

            'css_animation'    => '',

            'el_class'         => '',

        ), $atts

    );



    if ( ! $this->wc_actived ) {

        return;

    }



    $css_class = array(

        'supro-products-grid supro-products',

        'style-' . $atts['style'],

        $atts['btn_style'],

        $this->get_css_animation( $atts['css_animation'] ),

        'mobile-columns-' . $atts['m_columns'],

        $atts['el_class']

    );



    if ( $atts['load_more'] ) {

        $css_class[] = 'load-more-enabled';

    }



    $output = array();

    $title  = '';

    $filter = array();

    $type   = 'products';

    $attr   = array();



    $product_args = array(

        'limit'     => $atts['limit'],

        'columns'   => $atts['columns'],

        'page'      => 1,

        'orderby'   => $atts['orderby'],

        'order'     => $atts['order'],

        'category'  => '',

        'load_more' => $atts['load_more'],

    );



    $tabs = vc_param_group_parse_atts( $atts['tabs'] );



    if ( $atts['title'] ) {

        $title = sprintf( '<h3 class="title">%s</h3>', $atts['title'] );

    }



    if ( $atts['subtitle'] ) {

        $title .= sprintf( '<div class="subtitle">%s</div>', $atts['subtitle'] );

    }



    if ( $title ) {

        $title = '<div class="section-title">' . $title . '</div>';

    }



    if ( $atts['filter'] == 'category' ) {

        $attr = array(

            'limit'   => intval( $atts['limit'] ),

            'columns' => intval( $atts['columns'] ),

            'orderby' => $atts['orderby'],

            'order'   => $atts['order'],

        );



        if ( intval( $atts['show_all_product'] ) ) {

            $filter[] = sprintf(

                '<li class="active" data-filter="%s">%s</li>',

                $atts['category'] ? $atts['category'] : '',

                $atts['all_product_text']

            );

        } else {

            if ( $atts['category'] ) {

                $cats                     = explode( ',', $atts['category'] );

                $product_args['category'] = $cats[0];



            } else {

                $terms                    = get_terms( 'product_cat' );

                $empty_terms              = array();

                $new_terms                = array_merge( $terms, $empty_terms );

                $product_args['category'] = $new_terms[0]->slug;

            }

        }



        if ( $atts['category'] ) {

            $cats = explode( ',', $atts['category'] );



            foreach ( $cats as $cat ) {

                $cat      = get_term_by( 'slug', $cat, 'product_cat' );

                $filter[] = sprintf( '<li class="" data-filter="%s">%s</li>', esc_attr( $cat->slug ), esc_html( $cat->name ) );

            }

        } else {

            $terms = get_terms( 'product_cat' );



            foreach ( $terms as $term ) {

                $filter[] = sprintf( '<li class="" data-filter="%s">%s</li>', esc_attr( $term->slug ), esc_html( $term->name ) );

            }

        }



    } else {

        $product_args['category'] = $atts['category'];

        $css_class[]              = 'filter-by-group';



        if ( $tabs ) {

            $type = $tabs[0]['products'];



            $i = 0;

            foreach ( $tabs as $tab ) {

                $tab_attr = array(

                    'limit'   => intval( $atts['limit'] ),

                    'columns' => intval( $atts['columns'] ),

                    'orderby' => isset( $tab['orderby'] ) ? $tab['orderby'] : $atts['orderby'],

                    'order'   => isset( $tab['order'] ) ? $tab['order'] : $atts['order'],

                );

                if ( isset( $tab['title'] ) ) {

                    $filter[] = sprintf( '<li class="" data-filter="%s" data-attr="%s">%s</li>', esc_attr( $tab['products'] ), esc_attr( json_encode( $tab_attr ) ), esc_html( $tab['title'] ) );

                }



                if ( $i == 0 ) {

                    $atts['orderby'] = isset( $tab['orderby'] ) ? $tab['orderby'] : $atts['orderby'];

                    $atts['order']   = isset( $tab['order'] ) ? $tab['order'] : $atts['order'];

                }



                $i ++;

            }

        }

    }



    $link = '';



    if ( $atts['link'] && $atts['style'] == '3' ) {

        $link = '<div class="product-btn">' . $this->get_vc_link( $atts, '' ) . '</div>';

    }



    $filter_html = '<ul class="nav-filter filter">' . implode( "n", $filter ) . '</ul>';



    $output[] = $atts['style'] == '3' ? $title : '';

    $output[] = '<div class="product-header">';

    $output[] = $atts['style'] != '3' ? $title : '';

    $output[] = $filter_html;

    $output[] = $link;

    $output[] = '</div>';

    $output[] = '<div class="product-wrapper">';

    $output[] = '<div class="product-loading"><span class="supro-loader"></span></div>';

    $output[] = $this->get_wc_products( $product_args, $type );

    $output[] = '</div>';



    return sprintf(

        '<div class="%s" data-attr="%s" data-load_more="%s" data-nonce="%s">%s</div>',

        esc_attr( implode( ' ', $css_class ) ),

        esc_attr( json_encode( $attr ) ),

        esc_attr( $atts['load_more'] ),

        esc_attr( wp_create_nonce( 'supro_get_products' ) ),

        implode( '', $output )

    );

}

My two questions are :

  • how to hide all subcategory products
  • is it possible to make it thru functions.php ? Or should I overwrite the plugin Code ? Can I for example duplicate this bloc, with a new name in my child theme directly ?

NB : i already have this snippet to hide the subcategories in normal woocommerce category pages, and it works well there :

// cacher les produits des sous cat├ęgories
function exclude_product_cat_children($wp_query) {
if ( isset ( $wp_query->query_vars['product_cat'] ) && $wp_query->is_main_query()) {
    $wp_query->set('tax_query', array( 
                                    array (
                                        'taxonomy' => 'product_cat',
                                        'field' => 'slug',
                                        'terms' => $wp_query->query_vars['product_cat'],
                                        'include_children' => false
                                    ) 
                                 )
    );
  }
}  
add_filter('pre_get_posts', 'exclude_product_cat_children');

For example that is an image explain :

enter image description here


Get this bounty!!!

#StackBounty: #plugin-development #woocommerce Can woocommerse be used dynamically for billing from another plugin for payment processi…

Bounty: 50

I’m working on a plugin and rather than write my own payment processing code I was wondering if I could leverage woocommerce to do this. My plugin handles what amounts to rental spaces and all the custom management stuff is done with my plugin. It would be nice if there is a way for woocommerce to just to collect and log payments for my plugin. Is this possible? Most of the examples I’ve found about the API seem to apply to remote API use for woocommerce.

Thanks


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!

#StackBounty: #woocommerce #hooks #user-meta #profiles 'profile_update' hook alternative for WooCommerce user meta data

Bounty: 50

I am trying to get all user details (including WooCommerce meta data) in a function that is called with user_register and profile_update hooks. This is the simplified code:

function get_all_user_data($user_id) {

    $user_data = get_userdata($user_id);

    $login = $user_data->user_login;

    $b_firstname = get_user_meta($user_id, 'billing_first_name', true);

}
add_action('user_register','get_all_user_data');
add_action('profile_update','get_all_user_data');

The behavior:

  1. User is registered, I can access it’s userdata (e.g. login) immediately
  2. WooCommerce billing address is updated and saved, however I still only can access the $login variable, ‘billing_first_name’ meta is apparently still empty at this time
  3. WooCommerce shipping address is updated and saved, after this I can access the billing information that were saved in previous step, but not the shipping data that was saved in current step

The same goes for a scenario in which the user is registered during WooCommerce checkout, no WC data is accessible at that time yet.

PS: I have also tried the woocommerce_after_save_address_validation hook, but that seems to have the same behavior as the profile_update in my case.


Get this bounty!!!