enter image description here

On my woocommerce store I have the per-product shipping extension. If i duplicate one of my products the per-product shipping info is not copied. This is the information that I want to be copied when duplicated.

I found another question asking for this and they provided some code, however, it is not working for me.

add_action( 'woocommerce_product_duplicate', '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->get_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);



If anybody could help me with this it would be very much appreciated!

Read more here: Woocommerce – when duplicating a product it does not copy per-product shipping info


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: