Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi mikelee74, you will need to use the exposed WordPress Filters within our Plugin to copy the contents of $product->ID to $product->new_field within the woo_ce_product_item WordPress Filter, see:

    https://www.visser.com.au/blog/adding-static-product-fields-to-the-product-export-type/

    Hi mikelee74, you will need to use the exposed WordPress Filters within our Plugin to copy the contents of $product->ID to $product->new_field within the woo_ce_product_item WordPress Filter, see:

    https://www.visser.com.au/blog/adding-static-product-fields-to-the-product-export-type/

    Thread Starter mikelee74

    (@mikelee74)

    Sorry, but I’m not sure to understand.
    I have to insert in my function.php the following function?:

    function custom_woo_ce_extend_product_fields( $fields ) {

    $fields[] = array(
    ‘name’ => ‘static_field’,
    ‘label’ => __( ‘Static Field’, ‘woo_ce’ ),
    ‘hover’ => __( ‘Static Field within functions.php’, ‘woo_ce’ )
    );
    return $fields;

    }
    add_filters( ‘woo_ce_product_fields’, ‘custom_woo_ce_extend_product_fields’ );

    function custom_woo_ce_extend_product_item( $product, $product_id ) {

    $product->static_field = ‘Static value’;
    return $product;

    }
    add_filter( ‘woo_ce_product_item’, ‘custom_woo_ce_extend_product_item’, 10, 2 );

    and what I have to change?
    thank oyu

    Replace the 3rd last line within custom_woo_ce_extend_product_item().

    $product->static_field = ‘Static value’;

    to…

    $product->static_field = $product->ID;

    You can then rename the label element within the $fields[] array from ‘Static Field’ to ‘Duplicate Product ID’ or whatever name you want, do not change the name element without updating the reference in the other function. Give it a go ??

    Thread Starter mikelee74

    (@mikelee74)

    Hi,
    I add the following function in function.php file:
    —————————————-
    function custom_woo_ce_extend_product_fields( $fields ) {

    $fields[] = array(
    ‘name’ => ‘static_field2’,
    ‘label’ => __( ‘Duplicate Product ID’, ‘woo_ce’ ),
    ‘hover’ => __( ‘Static Field within functions.php’, ‘woo_ce’ )
    );
    return $fields;

    }
    add_filters( ‘woo_ce_product_fields’, ‘custom_woo_ce_extend_product_fields’ );

    function custom_woo_ce_extend_product_item( $product, $product_id ) {

    $product->static_field2 = $product->ID;
    return $product;

    }
    add_filter( ‘woo_ce_product_item’, ‘custom_woo_ce_extend_product_item’, 10, 2 );
    ———————————–
    I put “static_field2” because I have another static field in my function file, but it doesn’t work. The error is:
    Fatal error: Call to undefined function add_filters()

    thank you

    Hi mikelee74, when you copy and paste snippets they need to be exact. Change ‘add_filters’ to ‘add_filter’ ??

    Thread Starter mikelee74

    (@mikelee74)

    You are right! Thank!!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to duplicate products field in the export file?’ is closed to new replies.