How to set the meta description of a WooCommerce product as its primary category description?

Use the wpseo_metadesc filter: function wpse_406559_product_meta_description_from_category( $description ) { if ( ! is_singular( ‘product’ ) || $description ) { // Bail early if not single product, or custom meta description is already set return $description; } $product_cats = get_the_terms( get_queried_object_id(), ‘product_cat’ ); // Get first product category $product_cat = is_array( $product_cats ) ? current( $product_cats … Read more

Change product_base programmatically

Use your plugin activation hook to make the change. That will only run once, when your plugin is first activated, allowing the user to overwrite that change later (if they want to). register_activation_hook( __FILE__, function () { if ( $permalinks = get_option( ‘woocommerce_permalinks’ ) ) { $permalinks[‘product_base’] = ‘property’; update_option( ‘woocommerce_permalinks’, $permalinks ); flush_rewrite_rules(); } … Read more

A function to add arguments to a taxonomy

Use the filter register_taxonomy_args to manipulate the arguments used for registering the taxonomy just before it is registered: function wpse_406824_vendor_taxonomy_args( $args, $name ) { if ( $name === ‘dc_vendor_shop’ ) { $args[‘show_in_rest’] = true; $args[‘query_var’] = true; $args[‘show_ui’] = true; } return $args; } add_filter( ‘register_taxonomy_args’, ‘wpse_406824_vendor_taxonomy_args’, 10, 2 ); You’ll need to place this … Read more

Woocommerce check if email already created order recently [closed]

You can create a helper function for that which qurries the orders for given email and created less than 10 mins ago. function wpse407278_check_if_ordered_in_last_10_mins( $email ) { if ( !isset($email) || empty($email) ) { return false; } $args = array( ‘customer’ => $email, ‘date_created’ => ‘>’ . ( time() – strtotime(‘-10 minutes’) ), ); $orders … Read more

Remove ‘product’ & ‘product-cateogory’ from url – woocommerce [closed]

Found this neat little article on it, try this out! http://ryansechrest.com/2013/04/remove-post-type-slug-in-custom-post-type-url-and-move-subpages-to-website-root-in-wordpress/ It’s a guide/tutorial, so you should be able to get more information on what’s going on here if you visit his site. By the way, it’s against the rules to ask for a plugin here. add_action( ‘pre_get_posts’, ‘custom_pre_get_posts’ ); function custom_pre_get_posts($query) { global $wpdb; … Read more

Woocommerce display one random product via php

You could treat products like any other post type and query using get_posts(). Limit the number of posts retrieved to 1 and change the orderby parameter to random: $args = array( ‘posts_per_page’ => 1, ‘orderby’ => ‘rand’, ‘post_type’ => ‘product’ ); $random_products = get_posts( $args ); foreach ( $random_products as $post ) : setup_postdata( $post … Read more

Results not being printed

You’re _doing_it_wrong, as $product is an object. I’m pretty sure you want something like this: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 4, ); $featured_query = new WP_Query($args); if ($featured_query->have_posts()) { while ($featured_query->have_posts()) { $featured_query->the_post(); ?> <h1 class=”post-title”><?php the_title(); ?></h1> <div class=”post-content”><?php the_content(); ?></div> <?php } wp_reset_postdata(); }