// Set attribute name and value to search for $attribute_name = 'color'; $attribute_value = 'green'; $args = array( 'post_type' => 'product', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'pa_' . $attribute_name, 'field' => 'name', // can be 'slug' 'terms' => $attribute_value, ), ), ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) { $loop->the_post(); // do stuff here... e.g. get_the_ID() } wp_reset_postdata();
Archive by Author: Mekas
Query for WooCommerce products by product specific custom attribute
// Set custom attribute name and value to search for $attribute_name = 'color'; $attribute_value = 'green'; $serialized_value = serialize( 'name' ) . serialize( $attribute_name ) . serialize( 'value' ) . serialize( $attribute_value ); // extended version: $serialized_value = serialize( $attribute_name ) . 'a:6:{' . serialize( 'name' ) . serialize( $attribute_name ) . serialize( 'value' ) . serialize( $attribute_value ) . serialize( 'position' ); $args = array( 'post_type' => 'product', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => array( array( 'key' => '_product_attributes', 'value' => $serialized_value, 'compare' => 'LIKE', ), ), ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) { $loop->the_post(); // do stuff here... e.g. get_the_ID() } wp_reset_postdata();
Add Payment Method to WooCommerce Admin Email
add_action( 'woocommerce_email_after_order_table', 'add_payment_method_to_admin_new_order', 15, 2 ); function add_payment_method_to_admin_new_order( $order, $is_admin_email ) { if ( $is_admin_email ) { echo '<p><strong>Payment Method:</strong> ' . $order->payment_method_title . '</p>'; } }
Get site title in WordPress
$blog_title = get_bloginfo( 'name' );
Make all links clickable in WordPress text
$string = "This is a long text that contains some links like http://www.wordpress.org and http://www.wordpress.com ."; echo make_clickable($string);