post_type ) { return $actions; } $actions['duplicate'] = '' . __( 'Duplicate', 'woocommerce' ) . ''; return $actions; } /** * Show the dupe product link in admin. */ public function dupe_button() { global $post; if ( ! current_user_can( apply_filters( 'woocommerce_duplicate_product_capability', 'manage_woocommerce' ) ) ) { return; } if ( ! is_object( $post ) ) { return; } if ( 'product' !== $post->post_type ) { return; } if ( isset( $_GET['post'] ) ) { $notify_url = wp_nonce_url( admin_url( "edit.php?post_type=product&action=duplicate_product&post=" . absint( $_GET['post'] ) ), 'woocommerce-duplicate-product_' . $_GET['post'] ); ?>
set_id( 0 ); $duplicate->save(); $sku = $duplicate->get_sku(); if ( '' !== $duplicate->get_sku() ) { wc_product_force_unique_sku( $duplicate->get_id() ); } if ( $product->is_type( 'variable' ) || $product->is_type( 'grouped' ) ) { foreach( $product->get_children() as $child_id ) { $child = wc_get_product( $child_id ); $child_duplicate = clone $child; $child_duplicate->set_parent_id( $duplicate->get_id() ); $child_duplicate->set_id( 0 ); $child_duplicate->save(); if ( '' !== $child_duplicate->get_sku() ) { wc_product_force_unique_sku( $child_duplicate->get_id() ); } } } // Hook rename to match other woocommerce_product_* hooks, and to move away from depending on a response from the wp_posts table. // New hook returns new id and old id. do_action( 'woocommerce_product_duplicate', $duplicate, $product ); wc_do_deprecated_action( 'woocommerce_duplicate_product', array( $duplicate->get_id(), $this->get_product_to_duplicate( $product_id ) ), '2.7', 'Use woocommerce_product_duplicate action instead.' ); // Redirect to the edit screen for the new draft page wp_redirect( admin_url( 'post.php?action=edit&post=' . $duplicate->get_id() ) ); exit; } /** * Get a product from the database to duplicate. * * @deprecated 2.7.0 * @param mixed $id * @return WP_Post|bool * @see duplicate_product */ private function get_product_to_duplicate( $id ) { global $wpdb; $id = absint( $id ); if ( ! $id ) { return false; } $post = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE ID=$id" ); if ( isset( $post->post_type ) && 'revision' === $post->post_type ) { $id = $post->post_parent; $post = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE ID=$id" ); } return $post[0]; } } endif; return new WC_Admin_Duplicate_Product();