每个产品的送货延期信息重复 - WooCommerce

时间:2017-05-15 23:17:27

标签: php wordpress woocommerce

在我的wordpress网站上,我有WooCommerce和WooCommerce每个产品的送货延期(https://docs.woocommerce.com/document/per-product-shipping/)。我目前有一个问题,这就是每当我复制一个woocommerce产品时,不会复制每个产品的送货信息。我试图找到一个解决方案,并得到以下代码,但我无法让它工作,任何人都可以看到下面出了什么问题

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

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

   }
}

这是我想要复制的附加信息的示例 - Per Product Shipping Info

2 个答案:

答案 0 :(得分:0)

更新:Wordpress已修复此错误

答案 1 :(得分:-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 " . WC_PRODUCT_VENDORS_PER_PRODUCT_SHIPPING_TABLE . "
       Where product_id = '" . $id . "'";

       $result = $wpdb->get_results($query);
       $table_name =  WC_PRODUCT_VENDORS_PER_PRODUCT_SHIPPING_TABLE;

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