dimanche 22 novembre 2015

How do I add woocommerce custom field shortcode in sprintf?

I want to add custom field shortcode in cart product name. Right now, I don't know how to display custom field value, because the code is in sprintf.

I create a custom field in woocommerce product. The customs field is called color. I want the cart product name to print out the custom field value.

custom field shortcode

   <?php echo get_post_meta( get_the_ID(), 'color', true ); ?>

cart product name

                        <?php
                            if ( ! $_product->is_visible() ) {
                                echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;';
                            } else {
                                echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a class="items-info" href="%s">%s </a>', esc_url( $_product->get_permalink( $cart_item ) ), $_product->get_title() ), $cart_item, $cart_item_key );
                            }

                        ?>

For example,

My product name is "New york tee" and my custom field color value is "white" I want it to display like "New york tee - white" in my woocommerce cart product name. Also I want to add a dash before product name and custom field value. li "New york tee - white" Can someone help me? thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire