Get WooCommerce product attribute taxonomies in a SQL query on WordPress database

With WordPress to make a custom SQL query, you should always use the dedicated WPDB Class and related methods as get_results(), this way: global $wpdb; $results = $wpdb->get_results( ” SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies ” ); if ( count($results) > 0) { $data = []; // Initializing // Loop through results objects foreach( $results as $result … Read more

Show “Local Pickup” shipping method only for specific Woocommerce product categories [closed]

The following will only show “Local pickup” shipping method for specific product categories in cart: add_action( ‘woocommerce_package_rates’,’show_hide_local_pickup_shipping_methods’, 10, 2 ); function show_hide_local_pickup_shipping_methods( $rates, $package ) { // HERE BELOW your product categories in the array $categories = array( ‘t-shirts’, ‘hat’ ); $term_found = false; // Loop through cart items foreach( $package[‘contents’] as $cart_item ){ if( … Read more

Set download limit and expiry for WooCommerce downloadable products in specific categories

You can use WordPress conditional function has_term() to target specific product categories this way: // Set a different Download limit for specific downloadable products add_filter(‘woocommerce_product_get_download_limit’, ‘product_get_download_limit_filter_callback’, 30, 2 ); // Simple add_filter(‘woocommerce_product_variation_get_download_limit’, ‘product_get_download_limit_filter_callback’, 30, 2 ); // Variation function product_get_download_limit_filter_callback( $value, $product ) { $categories = array( ‘action’, ‘adventure’ ); // <== HERE define your … Read more

WooCommerce – Display variation custom field value [closed]

Ok, I’ve managed to solve this. This is how i finally created variations custom field: add_action( ‘woocommerce_product_after_variable_attributes’, ‘variation_settings_fields’, 10, 3 ); add_action( ‘woocommerce_save_product_variation’, ‘save_variation_settings_fields’, 10, 2 ); function variation_settings_fields( $loop, $variation_data, $variation ) { woocommerce_wp_text_input( array( ‘id’ => ‘price_1_50[‘ . $variation->ID . ‘]’, ‘class’ => ‘price_1_50’, ‘type’ => ‘text’, ‘label’ => __( ‘Price | Product … Read more

Get WooCommerce shipping methods programmatically

You need to use something different as following (commented): // Loop through shipping packages from WC_Session (They can be multiple in some cases) foreach ( WC()->cart->get_shipping_packages() as $package_id => $package ) { // Check if a shipping for the current package exist if ( WC()->session->__isset( ‘shipping_for_package_’.$package_id ) ) { // Loop through shipping rates for … Read more

Search product by brand name in wp_query

Founded: $filter_group_a = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => 18, ), array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘term_id’, ‘terms’ => 25, ), ); $filter_group_b = array( array( ‘taxonomy’ => ‘product_brand’, ‘field’ => ‘description’, ‘value’ => $tmp, ), ); $args = array( ‘post_type’ => ‘product’, ‘s’ => $tmp, ‘posts_per_page’ … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)