0
votes

Wordpress > WooCommerce > One Page Checkout

On a single product with One Page Checkout enabled, I have 3 variations of an attribute:

Product Variations Dashboard

When a variation is selected and Added to the Order, the One Page Checkout displays the Product Name, but does not include the variation:

One Page Checkout - No Variations Displayed

The variations ARE displayed in the full shopping cart, but are not when using One Page. When a customer is ordering multiple variations, this may be confusing for them.

I'd simply like to display the variation the customer has chosen alongside the Product Name using One Page Checkout.

Can anyone help?

PS: I apologize if this is the incorrect place to post. I'm new to the community, have taken only 1 class in Php and CSS, and have scoured Google and Stack for an answer. Hoping someone can help. Thank you in advance! :)

1
There is a change in WooCommerce 3.x that seems to remove the variation info from the cart item data and require plugins and themes to use get_name() instead of get_title() to get a product title that includes the variation info. Perhaps One Page Checkout has not been updated to reflect that change?Jake

1 Answers

3
votes

In WooCommerce 2.x, the variation attributes were displayed in the cart as meta data, however in WooCommerce 3.x they are included in the product name. But this requires a change to any cart customization in a plugin or theme to use the new WC_Product method get_name() instead of get_title().

If this is a third party plugin or theme, ideally you should find out if a new version is available that is fully compatible with WooCommerce 3.x and addresses the issue. But as a workaround, assuming the plugin/theme uses the filter hook woocommerce_cart_item_name, you can add the following to your theme's functions.php (if you are using a third party theme, you should create a child theme so that you don't lose your changes on updating it):

add_filter(
  'woocommerce_cart_item_name',
  function($name, $cart_item, $cart_item_key) {
    $product = apply_filters(
      'woocommerce_cart_item_product',
      $cart_item['data'],
      $cart_item,
      $cart_item_key
    );
    if (method_exists($product, 'get_name')) {
      // WooCommerce 3.x
      $is_link = substr($name, 0, 3) === '<a ';
      $name = $product->get_name();
      if ($is_link) {
        $name = sprintf(
          '<a href="%s">%s</a>',
          esc_url($product->get_permalink($cart_item)),
          $name
        );
      }
    }
    return $name;
  },
  50, 3
);