I’m trying to display product categories on each product in the list

Product categories in Woocommerce is a term, so you can get the categories with get_the_terms function: echo ‘<h3><a href=”‘ . get_the_permalink() . ‘”>’ . get_the_title() . ‘</a></h3>’; echo ‘<span style=”display:none;” class=”prodcat’; $categories = get_the_terms( get_the_ID(), ‘product_cat’ ); foreach ($categories as $category) { echo ‘ ‘ . $category->name . ”; }; echo ‘”> </span>’;

How to put a date range in a virtual/downloadable product? [closed]

Hook into add_to_cart hook add_action(‘woocommerce_add_to_cart’, ‘create_files_for_cart’); function create_files_for_cart() { // Your code that created the file using the dated the user selected // More code to add the file created to cart } The code to create the downloadable file product is similar to the code in this answer Add the product to cart with … Read more

Woocommerce – Dynamic Link to The Most Recently Added Product

This code will do what you want. It will redirect to the latest product added if you add ?latest_product to your site’s URL. So the dynamic link would be http://example.com/?latest_product function wpse_274155_redirect_latest_product() { // If URL has ?latest_product query string. if ( isset( $_GET[‘latest_product’] ) ) { // Get latest product. $latest_products = get_posts( array( … Read more

WooCommerce Admin Only Email Hook

The hook woocommerce_email_order_details has 4 parameters which can help you to identify the correct message. add_action( ‘woocommerce_email_order_details’, ‘so274215_add_transaction_id’, 10, 4); function so274215_add_transaction_id( $order, $sent_to_admin, $plain_text, $email ){ // decide here wether to show your transaction id if ( ! $sent_to_admin ) echo ‘<span style=”color:#555;font-size:1.5em;”>Transaction ID: ‘.get_post_meta( $order->id, “_transaction_id”, true ).'</span>’; } As far as I … Read more

Understanding WooCommerce Build-In Geolocation/ Geo_IP classes

This is how I used WooCommerce to get the country code on a recent project, using the geolocate_ip method of the WC_Geolocation class. $country = ‘US’; if (class_exists(‘WC_Geolocation’)) { $location = WC_Geolocation::geolocate_ip(”, true, false); if (isset($location[‘country’])) { $country = $location[‘country’]; } } switch ($country) { case ‘AU’: break; case ‘US’: break: }