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

I am using Woocommerce together with the WooThemes Per Product Shipping plugin.

The problem I have is that when using the “Duplicate” a product feature in Woocommerce, the PPS entries are not copied over to the new product.

Read More

Can anyone help in what I would need to add to the following file to get this to work?
https://github.com/woothemes/woocommerce/blob/master/includes/admin/class-wc-admin-duplicate-product.php

The PPS entries are stored in the following table:
http://www.awesomescreenshot.com/image/471866/f815997f78d9f2505919db880ffe35b5

Related posts

1 comment

  1. 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);
       }
    
       }
    }
    

Comments are closed.