- This topic has 11 replies, 2 voices, and was last updated 6 years, 2 months ago by
Tom.
-
AuthorPosts
-
September 18, 2017 at 7:26 pm #387715
David
StaffCustomer SupportHi Tom,
following on from the other thread. I would really like to convert this script to calling the woo function, in this instance for the Woo add to cart button.
function diggs_cart_button () { global $post , $product; $product_id = $product->get_id(); $product = wc_get_product( $product_id ); ob_start(); echo "<a href='".$product->add_to_cart_url()."'>add to cart</a>"; return ob_get_clean(); } add_shortcode ('diggs-cart-button', 'diggs_cart_button' );
I’m not that clued up on this and unsure about output buffering issues etc so any advice on whether it’s ok to use the above or if you can provide a better solution such as calling the action/filter inside the shortcode.
thanks
David
September 18, 2017 at 10:38 pm #387753Tom
Lead DeveloperLead DeveloperThe actual code looks ok.
I checked and couldn’t find a button related function from WC, but you can give the
<a>
element a class ofbutton
in order to turn it into a button.Unless of course you’re missing specific functionality from the default WC buttons?
September 19, 2017 at 2:52 am #387857David
StaffCustomer SupportHi Tom i appreciate you taking the time.
I would like the button to include the qty field.
I have codes for the title, short desc, long desc and price using the same method but they are all stripped of any style and particularly a problem all line breaks.Should I be concerned having this many echoes on one page? They seem to work ok
All of them are being used in GP headers. As an alternative is their a way of hooking the woo actions inside this?
September 19, 2017 at 8:42 pm #388425Tom
Lead DeveloperLead DeveloperHard finding any official documentation on this from Woo.
I did find this – perhaps it will help?: https://nicola.blog/2015/05/04/add-the-quantity-field-to-the-add_to_cart-shortcode/
September 20, 2017 at 8:21 am #388830David
StaffCustomer SupportHi Tom, thanks again for investigating.
EDIT: Yep it’s possible just add the action to a GP Hook. Now is there a way of hooking this inside the header?
The other issue i have is the shortcodes that pull in the description:
function diggs_full_desc () { global $post , $product; $product_id = $product->get_id(); $product = wc_get_product( $product_id ); ob_start(); echo '<div class="diggs_descrip">' . $product->get_description() . '</div>'; return ob_get_clean(); } add_shortcode ('diggs-full_desc', 'diggs_full_desc' );
This returns the correct output but without any of the line breaks. Any ideas?
thanks again
David
September 22, 2017 at 4:10 am #389928David
StaffCustomer SupportHi Tom, I discovered the inside merged header hook, so nice and simple to hook the add to cart inside the header area.
add_action( 'wp', 'tu_move_single_wc_addtocart_button' ); function tu_move_single_wc_addtocart_button() { remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_add_to_cart', 30 ); add_action( 'generate_inside_merged_page_header', 'woocommerce_template_single_add_to_cart', 30 ); }
Apart from the above text styling issues shop page headers are now complete. Can’t wait to share.
September 22, 2017 at 9:47 am #390106Tom
Lead DeveloperLead DeveloperAwesome! Sorry for not being more helpful here – on a small vacation. Which text styling issue are you having?
September 22, 2017 at 10:43 am #390135David
StaffCustomer SupportHi Tom, no problem – a well deserved break hey!
The text when pulled in via the above shortcode is stripped of all line breaks whereas in the actual woo description it is fine. The only fix i have so far would be to edit way too many product descriptions with <br> tags which wouldn’t be fun.
Any ideas?
September 22, 2017 at 11:25 pm #390364Tom
Lead DeveloperLead DeveloperCan you show me an example of some stripped text?
September 27, 2017 at 10:45 am #393017Tom
Lead DeveloperLead DeveloperIn your code, try replacing:
$product->get_description()
With:
wpautop( $product->get_description() )
September 29, 2017 at 3:43 am #394094David
StaffCustomer SupportTom, thank you again. This worked perfectly. David
September 29, 2017 at 9:01 am #394270Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.