php - Woocommerce if bought more than different one product -


in final step of checkout, show button if there 2 or more differente products, trying figure way count if there indeed 2 or more, tried this:

if (sizeof(wc()->cart->get_cart()) != 1) { echo '<a class="button emptycart" href="example-link">sample-text</a>'; } 

obviously no luck. tried doing different cases when knowing product id, when have 5, there 25 if statements accomplish task, like:

if ( woocommerce_customer_bought_product( $email, $current_user->id, '5898' )) && ( woocommerce_customer_bought_product( $email, $current_user->id, '5936' )){ echo '<a style="float: right; position: relative;margin-top: -35px;" class="button emptycart" href="sample">buy</a>'; }elseif ( woocommerce_customer_bought_product( $email, $current_user->id, '5935' )) && ( woocommerce_customer_bought_product( $email, $current_user->id, '5937' )){ echo '<a class="button emptycart" href="sample">buy</a>'; } 

and on... appreciated. thanks.

add_action( 'woocommerce_proceed_to_checkout', 'insert_empty_cart_button' );

function insert_empty_cart_button() {

//array store unique ids of product $unique_product_array=array();      // cycle through each product in cart     foreach( wc()->cart->cart_contents $prod_in_cart ) {         // variation or product id         $prod_id = ( isset( $prod_in_cart['variation_id'] ) && $prod_in_cart['variation_id'] != 0 ) ? $prod_in_cart['variation_id'] : $prod_in_cart['product_id'];          // check if product exist in array         if( in_array($prod_id,$unique_product_array) {     array_push($unique_product_array,$prod_id);         }     }  //check number of unique products in product array if(count($unique_product_array)>1) {     echo '<a class="button emptycart" href="example-link">sample-text</a>'; } } 

}?>

this code might achieve purpose. add appropriate hook require. here have added on 'woocommerce_proceed_to_checkout' work.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -