integration a class WC_Admin_Duplicate_Product and royal addon Woo Grid

[ad_1]

Hi, I want to extent the functionality of a plugin called “Royal addons” and it’s module woogrid. 

WooGrid module helps to display woocommerce product in elementor builder in various ways. I want to extent “manual selection” part, so that after selecting a product it creates a duplicate of that product in woocommerce (via build-in class [WC_Admin_Duplicate_Product](https://woocommerce.github.io/code-reference/classes/WC-Admin-Duplicate-Product.html)). 

And after selection, it will display the duplicated product So, to do the mentioned above duplication , I

 need to add a function that duplicates a product using woocommerce class WC_Admin_Duplicate_Product – here is it 


public function duplicate_selected_products( $selected_products ) {

if ( empty( $selected_products ) || ! class_exists( 'WC_Admin_Duplicate_Product' ) ) {

return [];

}

$duplicated_products = [];

foreach ( $selected_products as $product_id ) {

$duplicate_product = new WC_Admin_Duplicate_Product();

$new_product_id = $duplicate_product->product_duplicate( $product_id );

if ( $new_product_id ) {

$duplicated_products[] = $new_product_id;

}

}

return $duplicated_products;

    }

And the problem is that When I add this function to the file with woogrid module (called wpr-woo-grid.php) WordPress doesn’t access the woocommerce class

it shows an error Fatal error: Uncaught Error: Class WprAddons\Modules\WooGrid\Widgets\WC_Admin_Duplicate_Product’ not found in /home/winecard/public_html/wp-content/plugins/royal-elementor-addons/modules/woo-grid/widgets/wpr-woo-grid.php

I tried to use there requests with location of origial file 

require_once ‘/home/winecard/public_html/wp-content/plugins/woocommerce/include/admin/class-wc-admin-duplicate-product.php’; 

require_once WP_PLUGIN_DIR . ‘/woocommerce/includes/admin/class-wc-admin-duplicate-product.php’; 

require PATH_THIRD . ‘woocommerce/woocommerce.php’; 

I used this  $duplicate_product = new WooCommerce\Admin\WC_Admin_Duplicate_Product();

instead of this $duplicate_product = new WC_Admin_Duplicate_Product();  

How could I access the class woocommerce at royal addons plugin? thank you for your reply!

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer