How to change buy button link to go to product page before adding to cart
-
Hello everybody.
I use the woodmart theme and a plugin that adds fields for product variations, but for it to work the product needs to be classified as a simple product. But if I leave the product option simple, the theme generates the function of adding the product directly to the cart without the customer making the necessary choices to complete the order.
So what I need is to change the buy button link so that instead of adding to cart it goes to the product page in question.
Searching I found this code:
// Change the woocommerce add to cart button icon.
add_filter( ‘woocommerce_loop_add_to_cart_link’, ‘mwb_change_add_to_cart_button’, 10, 2 );
/**
* This function will chnagr the Add to cart button icon.
*
* @name mwb_change_add_to_cart_button
* @since 1.0.0
* @param string $add_to_cart Button for the Add to cart.
* @param array $product Array of the products.
* @author Mohit Mishra
* @link https://makewebbetter.com
*/
function mwb_change_add_to_cart_button( $add_to_cart, $product ) {
return sprintf( ‘%s‘,
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $quantity ) ? $quantity : 1 ),
esc_attr( $product->get_id() ),
esc_attr( $product->get_sku() ),
esc_attr( isset( $class ) ? $class : ‘button’ ),
esc_html( $product->add_to_cart_text() ),
esc_html__( $product->add_to_cart_text(),’text_domain’ )// put your textdomain here.
);
}
I tried some modifications but without success. Can anyone help me with this?
-
Hello,
So what I need is to change the buy button link so that instead of adding to cart it goes to the product page in question.
Are you referring to the buy button on the shop/category page? If you are trying to prevent the buy button from jumping directly to the cart page, please navigate to WooCommerce > Settings > Products > General > Add to cart behaviour, and uncheck “Enable AJAX add to cart buttons on archives.”
If this is not what you are referring to, please provide your page URL as well as System Status – you can find it via WooCommerce > Status. Select “Get system report” and then “Copy for support”. Once you’ve done that, paste it here in your response.
Are you referring to the buy button on the shop/category page? Yea But even disabling the ajax option in the woocommerce settings it still adds, not dynamically but adds and does not go to the product page, a function that I need for the customer to know that he needs to configure the product for his needs. this is the link to the shop page: https://www.loja.mx3design.com.br/produtos/ the sold out product is configured as a variable product and has the function I need, the button goes to the product but the other simple products are added directly to the cart.
### WordPress Environment ###
WordPress address (URL): https://www.loja.mx3design.com.br
Site address (URL): https://www.loja.mx3design.com.br
WC Version: 6.6.0
REST API Version: ? 6.6.0
WC Blocks Version: ? 7.6.0
Action Scheduler Version: ? 3.4.0
Log Directory Writable: ?
WP Version: 6.0
WP Multisite: –
WP Memory Limit: 512 MB
WP Debug Mode: –
WP Cron: ?
Language: pt_BR
External object cache: –### Server Environment ###
Server Info: LiteSpeed
PHP Version: 7.4.29
PHP Post Max Size: 512 MB
PHP Time Limit: 90
PHP Max Input Vars: 1000
cURL Version: 7.71.0
OpenSSL/1.1.1dSUHOSIN Installed: –
MySQL Version: 5.5.5-10.5.15-MariaDB-cll-lve
Max Upload Size: 512 MB
Default Timezone is UTC: ?
fsockopen/cURL: ?
SoapClient: ?
DOMDocument: ?
GZip: ?
Multibyte String: ?
Remote Post: ?
Remote Get: ?### Database ###
WC Database Version: 6.6.0
WC Database Prefix: wpuj_
Tamanho total do banco de dados: 20.89MB
Tamanho dos dados do banco de dados: 17.71MB
Tamanho do índice do banco de dado: 3.18MB
wpuj_woocommerce_sessions: Dados: 0.05MB + índex: 0.02MB + mecanismo InnoDB
wpuj_woocommerce_api_keys: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_woocommerce_attribute_taxonomies: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_woocommerce_downloadable_product_permissions: Dados: 0.02MB + índex: 0.06MB + mecanismo InnoDB
wpuj_woocommerce_order_items: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_woocommerce_order_itemmeta: Dados: 0.11MB + índex: 0.03MB + mecanismo InnoDB
wpuj_woocommerce_tax_rates: Dados: 0.02MB + índex: 0.06MB + mecanismo InnoDB
wpuj_woocommerce_tax_rate_locations: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_woocommerce_shipping_zones: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_woocommerce_shipping_zone_locations: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_woocommerce_shipping_zone_methods: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_woocommerce_payment_tokens: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_woocommerce_payment_tokenmeta: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_woocommerce_log: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_actionscheduler_actions: Dados: 0.05MB + índex: 0.11MB + mecanismo InnoDB
wpuj_actionscheduler_claims: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_actionscheduler_groups: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_actionscheduler_logs: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_cli_cookie_scan: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cli_cookie_scan_categories: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_cli_cookie_scan_cookies: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_cli_cookie_scan_url: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cli_scripts: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_commentmeta: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_comments: Dados: 0.02MB + índex: 0.09MB + mecanismo InnoDB
wpuj_cwmp_cart_abandoned: Dados: 0.00MB + índex: 0.00MB + mecanismo MyISAM
wpuj_cwmp_cart_abandoned_relation: Dados: 0.00MB + índex: 0.00MB + mecanismo MyISAM
wpuj_cwmp_newsletter_campanha: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_newsletter_send: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_order_bump: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_recupera_pedidos: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_send_thank: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_template_emails: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_cwmp_template_msgs: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_ezfc_debug: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_ezfc_files: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_ezfc_forms: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_ezfc_forms_elements: Dados: 0.27MB + índex: 0.02MB + mecanismo InnoDB
wpuj_ezfc_forms_options: Dados: 0.06MB + índex: 0.00MB + mecanismo InnoDB
wpuj_ezfc_forms_views: Dados: 0.23MB + índex: 0.16MB + mecanismo InnoDB
wpuj_ezfc_options: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_ezfc_preview: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_ezfc_submissions: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_ezfc_templates: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_e_events: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_e_submissions: Dados: 0.02MB + índex: 0.27MB + mecanismo InnoDB
wpuj_e_submissions_actions_log: Dados: 0.02MB + índex: 0.11MB + mecanismo InnoDB
wpuj_e_submissions_values: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_links: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_litespeed_url: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_litespeed_url_file: Dados: 0.02MB + índex: 0.08MB + mecanismo InnoDB
wpuj_options: Dados: 5.06MB + índex: 0.16MB + mecanismo InnoDB
wpuj_postmeta: Dados: 4.48MB + índex: 0.47MB + mecanismo InnoDB
wpuj_posts: Dados: 5.45MB + índex: 0.22MB + mecanismo InnoDB
wpuj_revslider_css: Dados: 0.13MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_css_bkp: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_layer_animations: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_revslider_layer_animations_bkp: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_revslider_navigations: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_revslider_navigations_bkp: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_revslider_sliders: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_sliders_bkp: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_slides: Dados: 0.16MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_slides_bkp: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_static_slides: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_revslider_static_slides_bkp: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_termmeta: Dados: 0.08MB + índex: 0.03MB + mecanismo InnoDB
wpuj_terms: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_term_relationships: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_term_taxonomy: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_usermeta: Dados: 0.05MB + índex: 0.03MB + mecanismo InnoDB
wpuj_users: Dados: 0.02MB + índex: 0.05MB + mecanismo InnoDB
wpuj_wc_admin_notes: Dados: 0.05MB + índex: 0.00MB + mecanismo InnoDB
wpuj_wc_admin_note_actions: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_wc_category_lookup: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_wc_customer_lookup: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_wc_download_log: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_wc_order_coupon_lookup: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_wc_order_product_lookup: Dados: 0.02MB + índex: 0.06MB + mecanismo InnoDB
wpuj_wc_order_stats: Dados: 0.02MB + índex: 0.05MB + mecanismo InnoDB
wpuj_wc_order_tax_lookup: Dados: 0.02MB + índex: 0.03MB + mecanismo InnoDB
wpuj_wc_product_attributes_lookup: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_wc_product_download_directories: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_wc_product_meta_lookup: Dados: 0.02MB + índex: 0.09MB + mecanismo InnoDB
wpuj_wc_rate_limits: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_wc_reserved_stock: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_wc_tax_rate_classes: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_wc_webhooks: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB
wpuj_woodmart_wishlists: Dados: 0.02MB + índex: 0.00MB + mecanismo InnoDB
wpuj_woodmart_wishlist_products: Dados: 0.02MB + índex: 0.02MB + mecanismo InnoDB### Post Type Counts ###
attachment: 628
cms_block: 31
cookielawinfo: 6
custom_css: 1
customize_changeset: 1
elementor_library: 3
mc4wp-form: 2
nav_menu_item: 65
page: 14
portfolio: 18
post: 20
product: 19
product_variation: 12
revision: 75
shop_order: 12
woodmart_layout: 1
woodmart_sidebar: 2
woodmart_size_guide: 2
woodmart_slide: 3
wp_global_styles: 1
wpcf7_contact_form: 3### Security ###
Secure connection (HTTPS): ?
Hide errors from visitors: ?### Active Plugins (22) ###
Cálculo do frete somente com o CEP – WC Brasil: por Alvaro Vasconcelos – @alvsconcelos – 1.1.1
Checkout Mestres WP: por Mestres do WP – 5.2.99997
Contact Form 7: por Takayuki Miyoshi – 5.6
GDPR Cookie Consent: por WebToffee – 2.1.2
Duplicate Page and Post: por Arjun Thakur – 2.7
Elementor Pro: por Elementor.com – 3.6.5
Elementor: por Elementor.com – 3.6.4
ez Form Calculator Premium: por Michael Schuppenies – 2.14.0.2
LiteSpeed Cache: por LiteSpeed Technologies – 4.6
Loco Translate: por Tim Whitlock – 2.6.2
Login No Captcha reCAPTCHA (Google): por Robert Peake and Contributors – 1.6.11
MC4WP: Mailchimp for WordPress: por ibericode – 4.8.7
Pinterest for WooCommerce: por WooCommerce – 1.1.0
Preenchimento Automatico CEP Brasil: por Mestres do WP – 1.5
Slider Revolution: por ThemePunch – 6.5.20
Safe SVG: por 10up – 2.0.1
Pix Automático com Pagarme para WooCommerce: por Marcos Gomes Neto – 1.5.2
Claudio Sanches – Correios for WooCommerce: por Claudio Sanches – 3.8.0
Brazilian Market on WooCommerce: por Claudio Sanches – 3.7.2
Pagar.me for WooCommerce: por Pagar.me
Claudio Sanches – 2.5.0WooCommerce: por Automattic – 6.6.0
Woodmart Core: por – 1.0.33### Inactive Plugins (2) ###
Advanced WordPress Reset: por Younes JFR. – 1.5
Jetpack: por Automattic – 11.0### Must Use Plugins (1) ###
Elementor Safe Mode: por Elementor.com – 1.0.0
### Settings ###
API Enabled: –
Force SSL: –
Currency: BRL (R$)
Currency Position: left_space
Thousand Separator: .
Decimal Separator: ,
Number of Decimals: 2
Taxonomies: Product Types: external (external)
grouped (grouped)
simple (simple)
variable (variable)Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)Connected to WooCommerce.com: –
Enforce Approved Product Download Directories: –### WC Pages ###
Base da loja: #5 – /produtos/
Carrinho: #6 – /carrinho/
Finaliza??o de compra: #7 – /finalizar-compra/
Minha conta: #8 – /minha-conta/
Termos e condi??es: ? Página n?o definida### Theme ###
Name: Woodmart Child
Version: 1.0.0
Author URL: https://xtemos.com
Child Theme: ?
Parent Theme Name: Woodmart
Parent Theme Version: 6.4.0 – 6.5.2 está disponível
Parent Theme Author URL: https://themeforest.net/user/xtemos
WooCommerce Support: ?### Templates ###
Overrides: woodmart/woocommerce/archive-product.php
woodmart/woocommerce/cart/cart-item-data.php
woodmart/woocommerce/cart/cart.php
woodmart/woocommerce/cart/cross-sells.php
woodmart/woocommerce/cart/mini-cart.php
woodmart/woocommerce/checkout/form-checkout.php
woodmart/woocommerce/checkout/thankyou.php
woodmart/woocommerce/content-product-cat.php
woodmart/woocommerce/content-product.php
woodmart/woocommerce/content-single-product.php
woodmart/woocommerce/content-widget-product.php
woodmart/woocommerce/global/breadcrumb.php
woodmart/woocommerce/global/form-login.php
woodmart/woocommerce/global/quantity-input.php
woodmart/woocommerce/loop/add-to-cart.php
woodmart/woocommerce/loop/loop-end.php
woodmart/woocommerce/loop/loop-start.php
woodmart/woocommerce/loop/no-products-found.php
woodmart/woocommerce/loop/orderby.php
woodmart/woocommerce/loop/pagination.php
woodmart/woocommerce/loop/sale-flash.php
woodmart/woocommerce/myaccount/form-login.php
woodmart/woocommerce/product-searchform.php
woodmart/woocommerce/single-product/add-to-cart/grouped.php
woodmart/woocommerce/single-product/add-to-cart/variable.php
woodmart/woocommerce/single-product/meta.php
woodmart/woocommerce/single-product/product-attributes.php
woodmart/woocommerce/single-product/product-image.php
woodmart/woocommerce/single-product/product-thumbnails.php
woodmart/woocommerce/single-product/rating.php
woodmart/woocommerce/single-product/related.php
woodmart/woocommerce/single-product/sale-flash.php
woodmart/woocommerce/single-product/tabs/description.php
woodmart/woocommerce/single-product/tabs/tabs.php
woodmart/woocommerce/single-product/title.php
woodmart/woocommerce/single-product/up-sells.php
woodmart/woocommerce/single-product.php### Admin ###
Enabled Features: activity-panels
analytics
coupons
customer-effort-score-tracks
experimental-products-task
experimental-import-products-task
experimental-fashion-sample-products
homescreen
marketing
mobile-app-banner
navigation
onboarding
onboarding-tasks
remote-inbox-notifications
remote-free-extensions
payment-gateway-suggestions
shipping-label-banner
subscriptions
store-alerts
transient-notices
wc-pay-promotion
wc-pay-welcome-page
wc-pay-subscriptions-pageDisabled Features: minified-js
settingsDaily Cron: ? Next scheduled: 2022-06-21 20:28:54 -03:00
Options: ?
Notes: 57
Onboarding: skipped### Action Scheduler ###
Concluído: 75
Oldest: 2022-06-18 13:41:08 -0300
Newest: 2022-06-21 11:15:40 -0300Pendente: 2
Oldest: 2022-06-21 17:51:34 -0300
Newest: 2022-06-21 17:51:34 -0300### Status report information ###
Generated at: 2022-06-21 13:19:17 -03:00
-
This reply was modified 2 years, 9 months ago by
marciomalfatti.
Thank you for the System Status
Upon checking your site, I can see that it’s not possible to access single product pages from your store.
As you have already observed, this behavior is created by your theme.From your System Status, it looks that most store templates on your site are based on the theme, and this is also the likely reason why custom WooCommerce functions won’t work either.
Since this forum is specific for the WooCommerce core plugin, I recommend that you check the Woodmart documentation, or contact the theme’s support channel:
- https://xtemos.com/documentation/woodmart/
- https://xtemos.com/forums/forum/woodmart-premium-template/
They will be best equipped to help you with that issue.
Regards
Good afternoon.
I understand, but I’m not getting the support needed by the theme.
If possible, I would like to understand how is the rule that determines the link for simple product and variable product for this button.
Seen in this code below, I couldn’t understand the rule.
( ‘woocommerce_loop_add_to_cart_link’,
sprintf( ‘<span>%s</span>‘,
esc_url( $product->add_to_cart_url() ),
esc_attr( isset( $args[‘quantity’] ) ? $args[‘quantity’] : 1 ),
esc_attr( isset( $args[‘class’] ) ? $args[‘class’] : ‘button’ ),
isset( $args[‘attributes’] ) ? wc_implode_html_attributes( $args[‘attributes’] ) : ”,
esc_html( $product->add_to_cart_text() )
),
If you can help me with this, I believe I can solve the rest.( 'woocommerce_loop_add_to_cart_link', sprintf( '<a href="%s" data-quantity="%s" class="%s add-to-cart-loop" %s><span>%s</span></a>', esc_url( $product->add_to_cart_url() ), esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ), esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ), isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', esc_html( $product->add_to_cart_text() ) ),
This is the code I tried to post above
Hi there,
This is a fairly complex development topic. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.
I can also recommend the WooCommerce Developer Resources Portal for resources on developing for WooCommerce.
You can also visit the WooCommerce Facebook group or the
#developers
channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.Hello everybody.
I appreciate everyone’s attention and help.
I was researching several call options to generate a link and leave only the css indicated so that the behavior of the button is for a variable product, and it worked uhuuuu
Below the code in case someone comes across this situation and needs the same solution.global $product; echo apply_filters( 'woocommerce_loop_add_to_cart_link', sprintf( '<a href="%s" data-quantity="%s" class="button product_type_variable add-to-cart-loop" %s><span>%s</span></a>', get_permalink( $product->id ), esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ), isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', esc_html( $product->add_to_cart_text() ) ), $product, $args );
-
This reply was modified 2 years, 9 months ago by
- The topic ‘How to change buy button link to go to product page before adding to cart’ is closed to new replies.