logo
down
shadow

WooCommerce - new shipping method - how to query individual product weights


WooCommerce - new shipping method - how to query individual product weights

Content Index :

WooCommerce - new shipping method - how to query individual product weights
Tag : php , By : Anna
Date : November 25 2020, 01:01 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

How to duplicate a Woocommerce product and include the WooThemes Per Product Shipping entries?


Tag : php , By : foxthrot
Date : March 29 2020, 07:55 AM
it helps some times I am using Woocommerce together with the WooThemes Per Product Shipping plugin. , You can use following code,
add_action( 'woocommerce_duplicate_product', 'wdm_duplicate_pps_entries',10,2);

function wdm_duplicate_pps_entries( $new_id, $post) {
   global $wpdb;
   $id = isset( $_REQUEST['post'] ) ? absint( $_REQUEST['post'] ) : '';
   if(!empty($id)) {
   $query = "Select * From " . $wpdb->prefix . "woocommerce_per_product_shipping_rule 
   Where product_id = '" . $id . "'";

   $result = $wpdb->results($query);
   $table_name =  $wpdb->prefix . "woocommerce_per_product_shipping_rule";

   foreach($result as $single_result) {

      $data = array('product_id' => $new_id, 'rule_country' => $single_result->rule_country, 'rule_state' => $single_result->rule_state,'rule_postcode' => $single_result->rule_postcode,'rule_cost' => $single_result->rule_cost,'rule_item_cost' => $single_result->rule_item_cost,'rule_order' => $single_result->rule_order);

     $wpdb->insert($table_name,$data);
   }

   }
}

(woocommerce) different shipping method per product


Tag : wordpress , By : Hugo
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , Yes per product shipping is possible in woocommerce, have you read this? There are also multiple Wordpress plugins to achieve this if the default behaviour doesn't fit your needs. I'm not gonna link them though, it's easeri for you to choose if you Google them :)

Disable a specific of flat rate shipping method for a selected product in Woocommerce


Tag : php , By : Jay Crockett
Date : March 29 2020, 07:55 AM
it should still fix some issue This can be done with the following function code, where you will define the related product ID and the shipping method ID to be disabled.
To find out the correct shipping method ID, just inspect with your browser dev tools the corresponding "flat rate" radio button under "value" argument.
add_filter('woocommerce_package_rates', 'product_hide_shipping_method', 10, 2);
function product_hide_shipping_method( $rates, $package ){
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return $rates;

    // HERE set your Shipping Method ID to be removed
    $shipping_method_id = 'flat_rate:12';

    // HERE set your targeted product ID
    $product_id = 37;

    $found = false;

    // Loop through cart items and checking for the specific product ID
    foreach( $package['contents'] as $cart_item ) {
        if( $cart_item['data']->get_id() == $product_id )
            $found = true;
    }

    if( $found ){
        // Loop through available shipping methods
        foreach ( $rates as $rate_key => $rate ){
            // Remove the specific shipping method
            if( $shipping_method_id === $rate->id  )
                unset($rates[$rate->id]);
        }
    }
    return $rates;
}
// HERE set your targeted product ID
$product_id = 37; 
// Define your targeted product IDs
$product_ids = array(37, 39, 52, 58);
if( $cart_item['data']->get_id() == $product_id )
if( in_array( $cart_item['data']->get_id(), $product_ids ) )
$cart_item['data']->get_id()
$cart_item['product_id']

Restore a discounted product price for a specific shipping method in Woocommerce


Tag : php , By : Waynew
Date : March 29 2020, 07:55 AM
will be helpful for those in need To restore cart items price based on a product category and on a specific chosen shipping method, try the following (for Woocommerce Dynamic Pricing):
add_filter('woocommerce_add_cart_item_data', 'add_default_price_as_cart_item_custom_data', 50, 3 );
function add_default_price_as_cart_item_custom_data( $cart_item_data, $product_id, $variation_id ){
    // HERE define your product category(ies)
    $categories = array('t-shirts');

    if ( has_term( $categories, 'product_cat', $product_id ) ) {
        $product_id = $variation_id > 0 ? $variation_id : $product_id;

        // The WC_Product Object
        $product = wc_get_product($product_id);

        // Get product default base price
        $price = (float) $product->get_price();

        // Set the Product default base price as custom cart item data
        $cart_item_data['default_price'] = $price;
    }
    return $cart_item_data;
}

add_action( 'woocommerce_before_calculate_totals', 'restore_cart_item_price', 900, 1 );
function restore_cart_item_price( $cart ) {
    if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;

    if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
        return;

    // HERE set the targeted Chosen Shipping method
    $targeted_shipping_method = 'local_pickup';

    // Get the chosen shipping method
    $chosen_methods            = WC()->session->get( 'chosen_shipping_methods' );
    $chosen_shipping_method_id = explode(':', reset($chosen_methods) );
    $chosen_shipping_method    = reset($chosen_shipping_method_id);

    // Loop through cart items
    foreach ( $cart->get_cart() as $cart_item ) {
        if( $targeted_shipping_method == $chosen_shipping_method && isset($cart_item['default_price']) ){
            // Set back the default cart item price
            $cart_item['data']->set_price($cart_item['default_price']);
        }
    }
}

Display the product shipping class on Woocommerce single product pages


Tag : php , By : Tom
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , You are getting the WP_term object and not the term nameā€¦ So instead use the following:
add_action('woocommerce_single_product_summary', 'display_specific_shipping_class', 15 );
function display_specific_shipping_class(){
    global $product;

    // HERE define your targeted shipping class name
    $defined_shipping_class = "Estimated Delivery in 7-15 days";

    // Get the product shipping class WP_Term Object
    $term = get_term_by( 'slug', $product->get_shipping_class(), 'product_shipping_class' );

    if( is_a($term, 'WP_Term') && $term->name == $defined_shipping_class ){
        echo '<p class="product-shipping-class">' . $term->name . '</p>';
    }
}
Related Posts Related QUESTIONS :
  • How to run scrapy with url parameters from php on linux debian
  • Preg matching imgur.com links
  • Php - Code comparing value of database to the value send by android app
  • Laravel pagination object in javascript
  • Error in validating message of no votes PHP
  • Symfony site on Azure with ClearDB connection
  • Woocommerce upsell with checkboxes
  • How to login/logout with Hybridauth 3?
  • Convert INT number in PHP
  • php/mysql. selecting 2 common fields in 2 tables
  • Expand an string based on values in an array in PHP
  • When you absolutely have to manually escape SQL in CakePHP 3.4.7
  • Htaccess redirecting wrong page
  • Laravel Optional WHERE clause
  • PHP unpack overlfow variable memory limit
  • How to check the URL's structure using PHP preg_match?
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com