Guest User

Untitled

a guest
Nov 21st, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. add_action('woocommerce_review_order_before_submit', 'add_pipletz_terms', 9);
  2. function add_pipletz_terms() {
  3.  
  4. // Show Terms 1
  5. $special_cat = 'insurance'; // HERE set your special category name, slug or ID
  6. $bool = false;
  7.  
  8. foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
  9. $item = $cart_item['data'];
  10. if ( has_term( 'insurance', 'product_cat', $item->id ) )
  11. $bool = true;
  12. }
  13.  
  14. if ( $bool ) {
  15. ?>
  16. <p class="form-row terms wc-terms-and-conditions">
  17. <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
  18. <input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox pipletz-terms" name="pipletz-terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['terms-1'] ) ), true ); ?> id="pipletz-terms"> <span><a href="https://businessbloomer.com/woocommerce-display-product-specific-tc-checkout/" target="_blank">I&rsquo;ve read and accept the Pipletz product terms & conditions</a></span> <span class="required">*</span>
  19. </label>
  20. </p>
  21. <?php
  22. }
  23. }
  24.  
  25. // If customer does not agree to terms
  26. add_action('woocommerce_checkout_process', 'not_approved_pipletz_terms');
  27. function not_approved_pipletz_terms() {
  28. if ( empty( $_POST['pipletz-terms'] ) ) {
  29. wc_add_notice( __( 'Please agree to the Pipletz product terms & conditions' ), 'error' ); }
  30. }
  31.  
  32. add_action('woocommerce_review_order_before_submit', 'add_pipletz_terms', 9 );
  33. function add_pipletz_terms() {
  34.  
  35. $special_cat = 'insurance'; // HERE set your special category name, slug or ID
  36. $bool = false;
  37.  
  38. foreach ( WC()->cart->get_cart() as $cart_item ) {
  39. // compatibility with WC +3
  40. $product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id();
  41. if ( has_term( $special_cat, 'product_cat', $product_id ) ){
  42. $bool = true;
  43. break; // added this too
  44. }
  45. }
  46.  
  47. if ( $bool ) {
  48. $link = 'https://businessbloomer.com/woocommerce-display-product-specific-tc-checkout/';
  49. ?>
  50. <p class="form-row terms wc-terms-and-conditions">
  51. <label class="woocommerce-form__label woocommerce-form__label-for-checkbox checkbox">
  52. <input type="checkbox" class="woocommerce-form__input woocommerce-form__input-checkbox input-checkbox pipletz-terms" name="pipletz-terms" <?php checked( apply_filters( 'woocommerce_terms_is_checked_default', isset( $_POST['pipletz-terms'] ) ), true ); ?> id="pipletz-terms">
  53. <span>
  54. <a href="<?php echo $link; ?>" target="_blank">I&rsquo;ve read and accept the Pipletz product terms & conditions</a>
  55. </span> <span class="required">*</span>
  56. </label>
  57. </p>
  58. <?php
  59. }
  60. }
  61.  
  62. // If customer does not agree to terms
  63. add_action('woocommerce_checkout_process', 'not_approved_pipletz_terms');
  64. function not_approved_pipletz_terms() {
  65.  
  66. $special_cat = 'insurance'; // HERE set your special category name, slug or ID
  67. $bool = false;
  68.  
  69. // Checking again if the category is in one cart item
  70. foreach ( WC()->cart->get_cart() as $cart_item ) {
  71. // compatibility with WC +3
  72. $product_id = version_compare( WC_VERSION, '3.0', '<' ) ? $cart_item['data']->id : $cart_item['data']->get_id();
  73. if ( has_term( $special_cat, 'product_cat', $product_id ) ){
  74. $bool = true;
  75. break; // added this too
  76. }
  77. }
  78.  
  79. if ( empty( $_POST['pipletz-terms'] ) && $bool )
  80. wc_add_notice( __( 'Please agree to the Pipletz product terms & conditions' ), 'error' );
  81. }
Add Comment
Please, Sign In to add comment