Skip to content

Instantly share code, notes, and snippets.

@Oscar-Abad-Folgueira
Last active May 10, 2020 11:59
Show Gist options
  • Save Oscar-Abad-Folgueira/af84930a1d1c178ae59f7773e11482f7 to your computer and use it in GitHub Desktop.
Save Oscar-Abad-Folgueira/af84930a1d1c178ae59f7773e11482f7 to your computer and use it in GitHub Desktop.
Forzar el uso de cupones en WooCommerce
<?php
/**
* @snippet Forzar el uso de cupones en WooCommerce
* @author Oscar Abad Folgueira
* @author_url https://www.oscarabadfolgueira.com
* @snippet_url https://www.oscarabadfolgueira.com/exigir-el-uso-de-cupones-en-woocommerce/
*/
add_action( 'woocommerce_check_cart_items', 'mandatory_coupon_code' );
function mandatory_coupon_code() {
$applied_coupons = WC()->cart->get_applied_coupons();
if( is_array($applied_coupons) && sizeof($applied_coupons) == 0 ) {
$message = __( 'Por favor, introduce un cupón.', 'woocommerce' );
wc_add_notice( $message, 'error' );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment