Support » Plugin: WooCommerce » Having different product names in front and backend

  • Resolved roberthising

    (@roberthising)


    Hey,

    I’m trying to get the backend of Woocommerce to show a different product name than the frontend. IE. the user should see one name but me and my shipping company should see a different name.

    I tried this:

    add_action( 'woocommerce_before_calculate_totals', 'custom_cart_items_prices', 10, 1 );
    function custom_cart_items_prices( $cart ) {
    
        if ( is_admin() && ! defined( 'DOING_AJAX' ) )
            return;
    
        if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
            return;
    
        // Loop through cart items
        foreach ( $cart->get_cart() as $cart_item ) {
    
            // Get an instance of the WC_Product object
            $product = $cart_item['data'];
    
            // Get the product name (Added Woocommerce 3+ compatibility)
            $original_name = method_exists( $product, 'get_name' ) ? $product->get_name() : $product->post->post_title;
    
            // SET THE NEW NAME
            $new_name = 'mydesiredproductname';
    
            // Set the new name (WooCommerce versions 2.5.x to 3+)
            if( method_exists( $product, 'set_name' ) )
                $product->set_name( $new_name );
            else
                $product->post->post_title = $new_name;
        }
    }

    But it changes the name on the cart, checkout and account pages as well as in the backend.

    Any suggestions??

Viewing 4 replies - 1 through 4 (of 4 total)
  • superkot

    (@superkot)

    By changing titles in the cart you of course change titles in the order which results from that cart. Properties of products in your orders exist independently of your actual shop products, because shop products may change or be removed and the orders need to keep whatever was actually ordered.

    It might be easier to filter whatever goes to your shipping company instead.

    roberthising

    (@roberthising)

    Oh, so it’s possible to just change the info that is sent to the shipping company? That would be fantastic!

    Any suggestions for how to accomplish that?

    All help is super appreciated!

    superkot

    (@superkot)

    That really depends on the way they are being sent, as that is obviously some custom code.

    roberthising

    (@roberthising)

    Figured as much. I’m talking to a developer to have it done.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Having different product names in front and backend’ is closed to new replies.