Created
January 19, 2025 08:13
-
-
Save gonzalesc/95a6d06ec16d1c1fa33295d57be53279 to your computer and use it in GitHub Desktop.
Convert your WooCommerce in catalog mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Convert your Ecommerce in catalog mode | |
* @package LetsGodev\MuPlugins | |
* @since 1.0 | |
*/ | |
// Hide the cart page & checkout page | |
add_action( 'template_redirect', 'hideCartCheckoutPage' ); | |
// All products must not be available for sale | |
add_filter( 'woocommerce_is_purchasable', '__return_false' ); | |
// Remove add-to-cart buttom from variations | |
add_action( 'woocommerce_before_add_to_cart_form', 'removeVariationAddToCartButton' ); | |
// add Contact Us button | |
add_action( 'woocommerce_single_variation', 'addContactUsButton', 20 ); | |
add_action( 'woocommerce_simple_add_to_cart', 'addContactUsButton', 30 ); | |
// Optional: hide minicart on StoreFront | |
add_action( 'wp_head', 'hideMiniCart' ); | |
/** | |
* Hide the cart page & checkout page | |
* @return void | |
*/ | |
function hideCartCheckoutPage(): void { | |
if ( is_cart() || is_checkout() ) { | |
wp_redirect( get_permalink( wc_get_page_id( 'shop' ) ) ); | |
exit; | |
} | |
} | |
/** | |
* Remove the call to the template | |
* @return void | |
*/ | |
function removeVariationAddToCartButton(): void { | |
remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 ); | |
} | |
/** | |
* Contact Us Button | |
* @return void | |
*/ | |
function addContactUsButton(): void { | |
$link = 'https://wa.link/zrgr7r'; | |
echo '<div class="woocommerce-variation-add-to-cart variations_button">'; | |
echo '<a href="'.$link.'" class="button add_to_cart_button wp-block-button__link wp-element-button wc-block-components-product-button__button has-text-align-center">ContactUs</a>'; | |
echo '</div>'; | |
} | |
/** | |
* Optional : Remove minicart front StoreFront theme | |
* @return void | |
*/ | |
function hideMiniCart(): void { | |
echo '<style>'; | |
echo '.site-header-cart { display: none; }'; | |
echo '</style>'; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment