I would recommend asking this question in the WooCommerce support forum: https://wordpress.org/support/plugin/woocommerce/
Hi @grayhunter
Could you use these codes to your child theme’s functions.php file or to this Code Snippets plugiin to add a View Product button to your shop poges?
/**
* Add ‘View Product’ button in WooCommerce
*/
add_action('woocommerce_after_shop_loop_item', 'wc_custom_button_view_product', 10 );
function wc_custom_button_view_product() {
global $product;
// Ignore for Variable and Group products
if( $product->is_type('variable') || $product->is_type('grouped') ) return;
// Display the custom button
echo '<a style="margin-left:5px" class="button wc-custom-button-view-product" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a>';
}
I would recommend using the Code Snippets plugin if you are not much familiar with PHP since adding the wrong codes to the child theme’s functions.php file may make the site offline.
And it’s best to ask WooCommerce related questions to the WooCommerce plugin support page: https://wordpress.org/support/plugin/woocommerce/
Thanks
Thank you so much!
For others – here is some more useful info about the solution.
The last question, please: What order should I use for the “Add to cart” and “View product” buttons?
In your sample it is 10 (‘wc_custom_button_view_product’, 10) for the “View product” button.
There are some plugins which have a position setting (“Above add to cart button” or “Under add to cart button”) – but this does not work if I have “View product” set to 10 and “Add to cart” to 15.
Please advise the correct position settings for the buttons.
@grayhunter ,
You can use this final code below to show Add To Cart first and View Product button last.
// Add "Add to Cart" buttons on Divi shop pages
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 5 );
/**
* Add ‘View Product’ button after ‘Add to Cart’ in WooCommerce
*/
add_action('woocommerce_after_shop_loop_item', 'wc_custom_button_view_product', 20 );
function wc_custom_button_view_product() {
global $product;
// Display the custom button
echo '<a style="margin-left:5px" class="button wc-custom-button-view-product" href="' . esc_attr( $product->get_permalink() ) . '">' . __('View product') . '</a>';
}
And this will be the result: https://prnt.sc/Qnt_VCKkkkkj
Hope this helps! 🙂
You are most welcome @grayhunter 🙂 Take Care 🙂