How to use WooCommerce Duplicate Product Class in functions.php

I am trying to use http://docs.woothemes.com/wc-apidocs/source-class-WC_Admin_Duplicate_Product.html#15-235 in functions.php but it does not work.

$wcx = new WC_Admin_Duplicate_Product;
$product = $wcx->duplicate_product('14466'));
print_r($product);

This gives me a blank page

Related posts

Leave a Reply

2 comments

  1. You need to change the method name to “product_duplicate()” and use “wc_get_product()” instead of “get_post()”

    $wc_adp = new WC_Admin_Duplicate_Product;
    $dproduct = $wc_adp->product_duplicate( wc_get_product( '62' ) );
    print_r( $dproduct );
    
  2. You need to use a wordpress post object as the parameter, not the post ID.
    Example:

    $wc_adp = new WC_Admin_Duplicate_Product;
    $product = $wc_adp->product_duplicate( get_post( '14466' ) );
    print_r( $product );