Created
October 27, 2015 22:54
-
-
Save kosmiq/d5bf5972a9bdd4b3d8d5 to your computer and use it in GitHub Desktop.
WooCommerce force order_comments if product in cart has category
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
/* | |
* Tvinga order_comments om en produkt finns i korgen som har "ticket" som kategori. Annars släpp förbi utan information. | |
*/ | |
add_action('woocommerce_checkout_process', 'order_notes_if_ticket'); | |
function order_notes_if_ticket( $order_id ){ | |
global $woocommerce; | |
//$categories[]; | |
foreach ($woocommerce->cart->cart_contents as $key => $values ) { | |
$terms = wp_get_post_terms( $values['product_id'], 'product_cat' ); | |
foreach ( $terms as $term ) $categories[] = $term->slug; | |
} | |
// Ändra "ticket" till den slug som kategorin har | |
if ( in_array( 'ticket', $categories ) && !$_POST['order_comments'] ) { // Ändra order_comments till det ID som fältet har. Mitt tema har inte "order_notes" som du nämnde på Twitter, fältet för "Ordernoteringar" heter "order_comments" i mitt tema. | |
wc_add_notice( __( 'Vänligen ange kostönskemål under ordernoteringar' ), 'error' ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment