Woocommerce returns Product post_status as published even tho it is in status draft

The solution is simple, delete the if check you’re having problems and add the post_status parameter to get_posts. For example: $args = [ ‘post_status’ => ‘publish’, ]; $only_published_posts = get_posts( $args ); Likewise we can pass an array of the statuses we do want, e.g. $args = [ ‘post_status’ => [ ‘publish’, ‘pending’ ], ]; … Read more

How do I display a user’s previous orders as a select box option on a product?

You can try something like this: add_action( ‘woocommerce_before_add_to_cart_form’, ‘add_list_completed_orders’ ); function add_list_completed_orders() { // get orders $orders = wc_get_orders ( array ( ‘status’ => array( ‘wc-completed’ ), ‘type’ => ‘shop_order’, ‘limit’ => -1, ‘return’ => ‘ids’, ‘customer_id’ => get_current_user_id(), ) ); if ( ! empty( $orders ) ) { // set value options $options=””; foreach … Read more

WooCommerce single products images doesn’t zoom on hover and doesn’t change clicking on gallery

my solution works for who makes a theme from zero (not using WordPress ready themes) make a Backup from your WordPress theme go to wp-content/plugins/woocommerce and find and copy a directory which name is templates into wp-content/themes/your-theme and rename it to woocommerce in your theme directory, create a file and name it woocommerce.php and add … Read more

HTML in WooCommerce settings

The woocommerce_clean function: return trim( strip_tags( stripslashes( $var ) ) ); is pretty much going to stip out any html. You may be able to use core WordPress sanitize and escaping functions, but no guarantee how WooCommerce is going to react. Take a look at Data Validation docs on the WordPress Codex for other options. … Read more

Top level parent taxonomy ID

In general to get the posts of your custom post type you need to query post_type, if you want only the categories you could just pull the categories instead of the entire post type. <?php query_posts(array( ‘post_type’ => ‘CustomPostType’ )); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php … Read more

How to update billing_email when user_email is updated [closed]

This code should do it for you. It add an action to the updating of the WordPress profile, checks if the email has been updated, and if so, it updates the Woocommerce address as well. add_action(‘profile_update’, ‘sync_woocommerce_email’, 10, 2) ; function sync_woocommerce_email( $user_id, $old_user_data ) { $current_user = wp_get_current_user(); if ($current_user->user_email != $old_user_data->user_email) { wp_update_user( … Read more