如何复制Woocommerce产品并包含WooThemes每件产品运输条目?

时间:2015-08-10 03:11:05

标签: php wordpress woocommerce woothemes

我正在使用Woocommerce和WooThemes Per Product Shipping插件。

我遇到的问题是,在Woocommerce中使用“复制”产品功能时,PPS条目不会复制到新产品。

任何人都可以帮助我需要添加到以下文件中以使其工作吗? https://github.com/woothemes/woocommerce/blob/master/includes/admin/class-wc-admin-duplicate-product.php

PPS条目存储在下表中: http://www.awesomescreenshot.com/image/471866/f815997f78d9f2505919db880ffe35b5

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码

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

   }
}