Look, it depends a lot on the theme. Woocommerce recommends the Storefront theme, which they do themselves and has a brutal coupling with the same plugin (some theme templates are read from the plugin ...).
In particular, almost everything that is drawn in the theme is associated with a hook.
I would start by creating a child theme. Maybe you already did it. A child theme inherits everything from the parent, so you could play with the child-theme without risking breaking the main theme, and on the other hand, when the main theme is updated, you will not lose everything you changed.
The themes are in wp-content/themes/
so to shorten the routes let's say that this subdirectory is <THEMES>
. That said, let's go to the most immediate example, what happens in the header.
If you check, you'll see that in the theme storefront there is hooks
associated with the action storefront_header
. In the file
<THEMES>/storefront/inc/woocommerce/storefront-woocommerce-template-hooks.php
It says:
add_action( 'storefront_header', 'storefront_product_search', 40 );
add_action( 'storefront_header', 'storefront_header_cart', 60 );
In the template
<THEMES>/storefront/header.php
The action is executed:
<header id="..." style="...">
<?php
do_action( 'storefront_header' );
?>
</header>
To understand the flow:
The declaration of the hooks above indicates that the storefront_product_search
and storefront_header_cart
are "hooked" to trigger when the action storefront_header
is called.
In the header the action is called, which executes the functions "hooked" to it. In this example, the functions storefront_product_search
and storefront_header_cart
that in particular write the search box and the cart widget that shows the total and can be displayed to see the detail.
If you would like something else to happen in the header, in your child theme (let's say it's storefront-child
) in
<THEMES>/storefront-child/header.php
You would remove or unhook hooks before calling action storefront_header
:
<header id="..." style="...">
<?php
remove_action('storefront_header', 'storefront_product_search', 40);
remove_action('storefront_header', 'storefront_header_cart', 60);
do_action( 'storefront_header' );
?>
</header>
The order in which they have been declared (40 and 60) are important at the time of deregistration.
For your particular case
Unlike the header, which is ultra generic and appears on all pages, you will have to dive what happens in the cart. Here comes the brutal coupling. The cart template is not in the theme storefront but in the woocommerce plugin . That seems crazy to me.
Anyway. I'm looking at the plugin and I think it's in
/wp-content/plugins/woocommerce/templates/cart/cart.php
In your child-theme, to overwrite that template you would have to create a woocommerce subdirectory, and within it the relative path. It's not intuitive because the route should be:
<THEMES>/storefront-child/woocommerce/cart/cart.php
(When common sense indicates that it should be <THEMES>/storefront-child/templates/...
)
The original template is full of actions
- woocommerce_cart_actions
- woocommerce_after_cart_contents
- woocommerce_after_cart_table
- woocommerce_cart_collaterals
- woocommerce_after_cart
And presumably there are some hooks hanging from such actions. You should find the hook, (in the original theme or in the woocommerce plugin) that draws the current checkout button and unregister it (s), and add the link you want in your template cart.php
.
You'll have to look for something that starts with (for example) add_action( 'woocommerce_cart_collaterals'
. But it may be more complicated and declared as (ex):
$prefix = 'woocommerce';
$section = 'cart';
add_action( $prefix.'_'.$section.'_collaterals', 'funcion_que_dibuja_boton-checkout', 50);
And that complicates everything. It entails a lot of research and much trial and error until you find the right action and your respective hook.
I can only wish you luck in the search.
A possible solution
Apparently the "checkout" button consists of several templates that together constitute a form. The form sends the transaction data to a default URL by WooComerce.
The start of the form is in
/wp-content/plugins/woocommerce/templates/checkout/form-checkout.php
And he says:
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data">
The action
attribute dictates where it is sent to the client. WooCommerce will deliver a value for wc_get_checkout_url()
according to the transaction. For example if it is a payment against delivery there is no payment gateway. Virtual type products do not have a shipping cost, etc. etc.
You could possibly play by creating means of payment in the WooCommerce dashboard, but the shortest way is to edit that template by stepping on it with a template in your theme, which you would put in:
<THEMES>/storefront-child/woocommerce/checkout/form-checkout.php
You copy the entire template and only change the action
attribute to send all the checkout data where it suits you. For example:
<form name="checkout" method="post" class="checkout woocommerce-checkout" action="<?php echo esc_url('http://mipasarela.com/pagar.php' ); ?>" enctype="multipart/form-data">
I hope it works.