Support » Plugin: Quantity Field on Shop Page for WooCommerce » Product name shows as undefined

  • Resolved tiagonandes

    (@tiagonandes)


    Hi. I’ve been having a problem when adding any product to cart as the green modal that pops up presents the product name as undefined instead of the actual product’s name. Issue can be seen here. (Translation: undefined was added to cart. Go to cart). This issue only happens when I enable this plugin.
    If you could look into it I’d really appreciate it. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author wooassist

    (@wooassist)

    @tiagonandes can you please send me a link to your site so we could inspect?

    Thread Starter tiagonandes

    (@tiagonandes)

    @wooassist here it is. Thank you.

    Plugin Author wooassist

    (@wooassist)

    @tiagonandes I have checekd your site and this is not the default behavior of woocommerce. I think your theme may be using a custom function for the add to cart. if you have a test site pls try testing again using a default theme or storefront and see if you still hav ethe same issue. also try checking for plugin conflicts by disabling all plugins except woocommerce and enabling them again 1 by 1 so you can find the culprit.

    Thread Starter tiagonandes

    (@tiagonandes)

    @wooassist Thanks for your answer, I have tried what you suggested and it turns out the theme needed the attribute data-title from the button with the product name, which your plugin does not have defined. If anyone is having the same problem, all I did was add data-title="'. $product->get_name() .'" to the plugin’s button html.

    public function woa_add_quantity_fields($html, $product) {
    		//add quantity field only to simple products
    	if ( $product && $product->is_type( 'simple' ) && $product->is_purchasable() && $product->is_in_stock() && ! $product->is_sold_individually() ) {
    		//rewrite form code for add to cart button
    		$html = '<form action="' . esc_url( $product->add_to_cart_url() ) . '" class="cart" method="post" enctype="multipart/form-data">';
    		$html .= woocommerce_quantity_input( array(), $product, false );
    		$html .= '<button type="submit" data-quantity="1" data-title="'. $product->get_name() .'" data-product_id="' . $product->get_id() . '" class="button alt ajax_add_to_cart add_to_cart_button product_type_simple">' . esc_html( $product->add_to_cart_text() ) . '</button>';
    		$html .= '</form>';			
    	}
    	return $html;
    	}
    Plugin Author wooassist

    (@wooassist)

    @tiagonandes thanks for your support. its great that you have found a solution for this.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Product name shows as undefined’ is closed to new replies.