<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Highly Responsive</title>
	<atom:link href="https://highlyresponsive.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://highlyresponsive.com/</link>
	<description>Responsive Web Solutions</description>
	<lastBuildDate>Thu, 26 Feb 2026 16:24:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://highlyresponsive.com/wp-content/uploads/2024/04/highly.repsonsive.icon-500px-150x150.png</url>
	<title>Highly Responsive</title>
	<link>https://highlyresponsive.com/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How To Customize Kadence Theme With Code Snippets</title>
		<link>https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/</link>
					<comments>https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/#respond</comments>
		
		<dc:creator><![CDATA[hradmin]]></dc:creator>
		<pubDate>Mon, 13 Oct 2025 17:56:29 +0000</pubDate>
				<category><![CDATA[Code Snippets]]></category>
		<guid isPermaLink="false">https://highlyresponsive.com/?p=6115</guid>

					<description><![CDATA[<p>Here’s a concise set of code snippets to tailor the Kadence theme and its features to your needs. I’ve used Kadence on a long list of websites and found it to be a highly flexible and powerful theme. That said, ... </p>
<p class="read-more-container"><a title="How To Customize Kadence Theme With Code Snippets" class="read-more button" href="https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/#more-6115" aria-label="Read more about How To Customize Kadence Theme With Code Snippets">Read More</a></p>
<p>The post <a href="https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/">How To Customize Kadence Theme With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Here’s a concise set of code snippets to tailor the Kadence theme and its features to your needs. I’ve used Kadence on a long list of websites and found it to be a highly flexible and powerful theme. That said, some features still require adding a few code snippets to your (child) theme’s functions.php file or through a code snippets plugin to unlock their full potential.</p>



<p>If you’re new to Kadence or need a refresher, check out the official <a href="https://www.kadencewp.com/help-center/knowledge-base/kadence-theme/">Kadence Documentation</a>. It offers straightforward help articles to get you started.</p>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading">Only Show Updated or Published Date on Posts, Not Both, in the Post Meta on Kadence Theme</h2>



<p>Some SEOs and others in the industry are recommending to only show the Last Modified or Updated date in the header post meta for blog posts instead of showing both the published and last modified/updated date. I won&#8217;t get into the details of why or whether it&#8217;s necessary, but this is a common change we&#8217;re seeing by some in the industry. Kadence does not allow us to filter the post meta, but it does offer action hooks to add code after the post meta. By hiding the dates under Single Post Layout in the Customizer, we can add the code below to achieve the desired effect of one date &#8211; &#8220;Published on&#8221; date if the post has no last modified/updated date or if the last modified/updated date is less than 7 days from the Published date <strong>OR</strong> &#8220;Updated on&#8221; date if the post has been updated more than 7 days after the original published date.</p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">/* Important Note: Be sure to turn off dates in Single Post Layout in the Customizer for this to make sense. You cannot rearrange the other post meta due to Kadence limitations without further custom coding. */
add_action('kadence_after_entry_meta','custom_post_dates');
function custom_post_dates(){
 $date = get_the_time( 'U' );
 $updated = get_the_modified_time( 'U' );
 $time_string = '&lt;span class="posted-on">&lt;span class="meta-label">Published on&lt;/span>&lt;time class="entry-date published updated" datetime="%1$s">%2$s&lt;/time>';
 if ( $date !== $updated &amp;&amp; $updated > ($date + WEEK_IN_SECONDS)) {
  $time_string = '&lt;span class="updated-on">&lt;span class="meta-label">Updated on&lt;/span>&lt;time class="updated" datetime="%3$s">%4$s&lt;/time>';
 }
 $time_string = sprintf(
  $time_string,
  esc_attr( get_the_date( 'c' ) ),
  esc_html( get_the_date() ),
  esc_attr( get_the_modified_date( 'c' ) ),
  esc_html( get_the_modified_date() )
 );
 if(! empty($time_string)){
  echo $time_string . '&lt;/span>';
 }
}</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<p>Leave your ideas, requests, or feedback on these code snippets below in the comments. Thanks!</p>
<p>The post <a href="https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/">How To Customize Kadence Theme With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://highlyresponsive.com/how-to-customize-kadence-theme-with-code-snippets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Customize WooCommerce with Code Snippets</title>
		<link>https://highlyresponsive.com/woocommerce-code-snippets/</link>
					<comments>https://highlyresponsive.com/woocommerce-code-snippets/#respond</comments>
		
		<dc:creator><![CDATA[hradmin]]></dc:creator>
		<pubDate>Fri, 28 Feb 2020 23:32:06 +0000</pubDate>
				<category><![CDATA[Code Snippets]]></category>
		<guid isPermaLink="false">https://highlyresponsive.com/?p=2433</guid>

					<description><![CDATA[<p>This is a growing collection of code snippets to customize WooCommerce. As an experienced WooCommerce developer, I have written and used countless code snippets. The code snippets below are either unique, custom solutions or are extremely useful ones that I ... </p>
<p class="read-more-container"><a title="How to Customize WooCommerce with Code Snippets" class="read-more button" href="https://highlyresponsive.com/woocommerce-code-snippets/#more-2433" aria-label="Read more about How to Customize WooCommerce with Code Snippets">Read More</a></p>
<p>The post <a href="https://highlyresponsive.com/woocommerce-code-snippets/">How to Customize WooCommerce with Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is a growing collection of code snippets to customize WooCommerce. As an experienced WooCommerce developer, I have written and used countless code snippets. The code snippets below are either unique, custom solutions or are extremely useful ones that I use regularly.</p>



<p>If you&#8217;re familiar with WordPress coding at all, make sure to visit  the official <a href="https://docs.woocommerce.com/wc-apidocs/hook-docs.html" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">WooCommerce Hook Reference</a> where you can find extensive documentation of all the WooCommerce hooks and filters.</p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">WooCommerce Product Listing Only Site (Disable Purchases)</h2>



<p>This simple WooCommerce code snippet is designed for a unique circumstance where you want a product listing on your website, but don&#8217;t want anyone to actually purchase anything. Scenarios where I&#8217;ve found this useful are retail businesses that sell big ticket items that don&#8217;t ship easily like cars, RVs, industrial equipment, etc. However, they still want to show their products and inventory on their website. Of course, there may be a few cases where store owners just don&#8217;t want to sell online yet as well.  Using WooCommerce to control your product listings can be super helpful if you are synchronizing data between WooCommerce and inventory management or POS software. If you are using this solution, you should make sure that your payment methods are all disabled as an obvious additional measure of preventing any purchases. The second part of the code snippet ensures that visitors cannot access the cart or the checkout pages as well just as a backup measure. The code should be inserted into the (child) theme&#8217;s functions.php file. </p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">/* Prevent products from being added to cart */
add_filter( 'woocommerce_is_purchasable', '__return_false');
/* Redirect non-admin users away from cart and checkout pages */
add_action( 'template_redirect', 'redirect_non_logged_in_user' );
function redirect_non_logged_in_user(){
    if ( !is_user_logged_in() &amp;&amp; (is_page('cart') || is_page('checkout')) ) {
            wp_redirect( site_url() );  exit;
    }
}</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Change WooCommerce Read More Button Text</h2>



<p>This code snippet goes hand-in-hand with the snippet found above. When you disable the ability to purchase products on a site, the &#8216;Add to Cart&#8217; button text changes to &#8216;Read More&#8217;. In order to change that text to something more appropriate for product information like &#8216;View Details&#8217;, you need to add the following code snippet to your (child) theme&#8217;s functions.php file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Change Read More text to View Details with purchasing turned off */
add_filter( 'woocommerce_product_add_to_cart_text', 'custom_woocommerce_product_add_to_cart_text', 10 );
function custom_woocommerce_product_add_to_cart_text( $text ) {

    // First make sure that we are only replacing 'Read more'
    $wc_read_more = __( 'Read more', 'woocommerce' );

    if( $text !== $wc_read_more ){
        return $text;
    }else{
        return __( 'View Details', 'woocommerce' );
		}
}</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Change WooCommerce Related Products Text</h2>



<p>A common need is to change the text that shows in the Related Products area. Some store owners rather have text that says &#8216;Recommended Products&#8217;  or &#8216;Other Products You May Like&#8217; or something else. This basic code snippet shows how to  change that text.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Change WooCommerce "Related products" text */
add_filter('gettext', 'change_woo_related_products_text', 10, 3);
add_filter('ngettext', 'change_woo_related_products_text', 10, 3);
function change_woo_related_products_text($translated, $text, $domain)
{
     if ($text === 'Related products' &amp;&amp; $domain === 'woocommerce') {
         $translated = esc_html__('Recommended Products', $domain);
     }
     return $translated;
}</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Add Custom Fields to WooCommerce Products (Admin)</h2>



<p>This is not a unique code snippet or customization on WooCommerce sites. This is a quick reference of a two of the most popular hooks that allow you to add custom fields (stored as meta) to WooCommerce products in the Admin area and save the data (stored as postmeta). You need to replace the function names and fields with your own before implementing the following code snippet which could be placed in the (child) theme&#8217;s functions.php file or as part of a standalone plugin.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Add custom WooCommerce product field after the SKU field in the Inventory tab */
function try_add_custom_field() {
	$args = array(
		'label' => __( 'Custom Field', 'woocommerce' ),
		'placeholder' => __( 'Custom Field Placeholder Text', 'woocommerce' ),
		'id' => 'try_custom_field', // field name stored in database for retrieval and update
		'desc_tip' => true,
		'description' => __( 'This is a tooltip box for detailed information on the field.', 'woocommerce' ),
	);
	woocommerce_wp_text_input( $args );
}
// This hook located the custom field after the SKU field in the Inventory tab
add_action( 'woocommerce_product_options_sku', 'try_add_custom_field' );

/* Function to save the custom data you just created for the custom field */
function try_save_custom_field( $post_id ) {
	$try_custom = isset( $_POST[ 'try_custom_field' ] ) ? sanitize_text_field( $_POST[ 'try_custom_field' ] ) : '';
	$product = wc_get_product( $post_id );
	$product->update_meta_data( 'try_custom_field', $try_custom );
	$product->save();
}
add_action( 'woocommerce_process_product_meta', 'rv_save_custom_sku' );

/* Alternative hook to 'woocommerce_product_options_sku' that adds custom field to General Tab */
add_action( 'woocommerce_product_options_general_product_data', 'try_add_custom_field' );</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Crop and Set Width and Height for WooCommerce Single Product Image</h2>



<p>It took a little effort to figure out the correct way to not only set the width of the Single Product Image &#8211; which can be done in the Customizer-&gt;WooCommerce-&gt;Product Images &#8211; but also set a height and crop the image. When showing a gallery of various sizes and aspect ratios of product images, the gallery is hard to consistently control where the thumbnails are located for gallery navigation. One image might be wide. One image might be tall. So when scrolling between those images, it causes difficulty for the user to be able to see and click the thumbnails for that gallery without them jumping up and down the page. This very simple code snippet allows you to set the width and height and crop the images. WooCommerce should automatically regenerate thumbnails, but you should double-check. If WooCommerce does not automatically regenerate the thumbnails (which has always worked for me), it&#8217;s an easy solution to use <a rel="noreferrer noopener" aria-label="Regenerate Thumbnails (opens in a new tab)" href="https://wordpress.org/plugins/regenerate-thumbnails/" target="_blank">Regenerate Thumbnails</a>. Also don&#8217;t forget to bulk optimize the new thumbnails if your image optimization plugin doesn&#8217;t automatically handle it for you.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Set size for single product image on individual product pages */
add_filter( 'woocommerce_get_image_size_single', function( $size ) {
	return array(
		'width'  => 441,
		'height' => 441,
		'crop'   => 1,
	);
} );</code></pre>
<p>The post <a href="https://highlyresponsive.com/woocommerce-code-snippets/">How to Customize WooCommerce with Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://highlyresponsive.com/woocommerce-code-snippets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Customize WCMp (now MultivendorX) With Code Snippets</title>
		<link>https://highlyresponsive.com/multivendorx-code-snippets/</link>
					<comments>https://highlyresponsive.com/multivendorx-code-snippets/#respond</comments>
		
		<dc:creator><![CDATA[hradmin]]></dc:creator>
		<pubDate>Fri, 28 Feb 2020 22:28:42 +0000</pubDate>
				<category><![CDATA[Code Snippets]]></category>
		<guid isPermaLink="false">https://highlyresponsive.com/?p=2412</guid>

					<description><![CDATA[<p>WCMp, also known as WC Marketplace, is one of the most popular and powerful multi-vendor plugins for WordPress and WooCommerce. Recently, WCMp rebranded itself and is now called MultivendorX. WCMp (MultivendorX) is an excellent solution at a modest price &#8211; ... </p>
<p class="read-more-container"><a title="How To Customize WCMp (now MultivendorX) With Code Snippets" class="read-more button" href="https://highlyresponsive.com/multivendorx-code-snippets/#more-2412" aria-label="Read more about How To Customize WCMp (now MultivendorX) With Code Snippets">Read More</a></p>
<p>The post <a href="https://highlyresponsive.com/multivendorx-code-snippets/">How To Customize WCMp (now MultivendorX) With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>WCMp, also known as WC Marketplace, is one of the most popular and powerful multi-vendor plugins for WordPress and WooCommerce. Recently, WCMp rebranded itself and is now called MultivendorX. WCMp (MultivendorX) is an excellent solution at a modest price &#8211; the core plugin is free. There will always be shortcomings when you&#8217;re trying to develop a solution as complex as a multi-vendor marketplace. In order to fully customize your WCMp project, you&#8217;ll need to implement custom code snippets applied via hooks and filters. If you are new to WCMp customizations, the <a href="https://multivendorx.com/support-forum/">MultivendorX Support Forum</a> is a good place to start.</p>



<p>In my development experience with WC Marketplace (MultivendorX), I have written and used many code snippets but the code snippets below have proven to be very useful and time saving for my projects and my clients. Below are the best WCMp code snippets that you won&#8217;t find anywhere else.</p>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading">Bulk Duplicate Products for Vendors</h2>



<p>When utilizing the SPMV (Single Product Multiple Vendor) feature in WCMp, duplicating products can be a slow process. Each product has to be duplicated individually. When you have 50-100 products and double-digit numbers of vendors that all carry a majority of those products, the time it takes to duplicate those products is hard to fathom. This custom solution I developed can be inserted into the (child) theme&#8217;s functions.php file or could potentially be used to create a standalone plugin. </p>



<p class="has-small-font-size"><strong>Warning: This code snippet can result intense server resource usage when duplicating a large amount of products and can potentially cause server downtime if you overload the server. I recommend using this bulk action method of duplicating products in small batches of 10-30 products at a time depending on your server. The amount of time to process such requests may vary depending on server as well. More powerful VPS or dedicated servers may be able to handle processing bigger batches.</strong></p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">// Add new action to bulk action drop-down menu labeled "Copy for Vendor"
add_filter( 'bulk_actions-edit-product', 'duplicate_product_to_vendor_register_bulk_action' );
// Main duplication process handler
add_filter( 'handle_bulk_actions-edit-product', 'duplicate_product_to_vendor_action_handler', 10, 3 );
// Notification after duplicating products
add_action( 'admin_notices', 'duplicate_product_to_vendor_bulk_action_notices' );

function duplicate_product_to_vendor_bulk_action_notices() {
	if ( ! empty( $_REQUEST['duplicate_product_to_vendor_done'] ) ) {
		echo '&lt;div id="message" class="updated notice is-dismissible"&gt;
			&lt;p&gt;Duplicate product(s) created. Now assign to vendor and publish.&lt;/p&gt;
		&lt;/div&gt;';
	}
}

function duplicate_product_to_vendor_register_bulk_action($bulk_actions) {
	$bulk_actions['duplicate_product_to_vendor'] = __( 'Copy for Vendor', 'duplicate-post');
	return $bulk_actions;
}

function duplicate_product_to_vendor_action_handler( $redirect, $action, $post_ids ) {
	$redirect = remove_query_arg( 'duplicate_product_to_vendor_done', $redirect );
	if ( $action !== 'duplicate_product_to_vendor' ) {
		return $redirect;
	}
	global $WCMp;
	$counter = 0;
	foreach ( $post_ids as $post_id ) {
		$parent_post = get_post($post_id);
		if(!empty($parent_post)){
			$product = wc_get_product($post_id);
			if (!function_exists('duplicate_post_plugin_activation')) {
					include_once( WC_ABSPATH . 'includes/admin/class-wc-admin-duplicate-product.php' );
			}
			$duplicate_product_class = new WC_Admin_Duplicate_Product();
			$duplicate_product = $duplicate_product_class-&gt;product_duplicate($product);
			if ($duplicate_product) {
			        // if product title has Copy string, remove
				$title = str_replace(" (Copy)", "", $parent_post-&gt;post_title);
				wp_update_post(array('ID' =&gt; $duplicate_product-&gt;get_id(), 'post_author' =&gt; $duplicate_to_vendor, 'post_title' =&gt; $title));
				wp_set_object_terms($duplicate_product-&gt;get_id(), absint(get_current_vendor()-&gt;term_id), $WCMp-&gt;taxonomy-&gt;taxonomy_name);
				// Add GTIN, if exists
				$gtin_data = wp_get_post_terms($product-&gt;get_id(), $WCMp-&gt;taxonomy-&gt;wcmp_gtin_taxonomy);
				if ($gtin_data) {
					$gtin_type = isset($gtin_data[0]-&gt;term_id) ? $gtin_data[0]-&gt;term_id : '';
					wp_set_object_terms($duplicate_product-&gt;get_id(), $gtin_type, $WCMp-&gt;taxonomy-&gt;wcmp_gtin_taxonomy, true);
				}
				$gtin_code = get_post_meta($product-&gt;get_id(), '_wcmp_gtin_code', true);
				if ($gtin_code)
					update_post_meta($duplicate_product-&gt;get_id(), '_wcmp_gtin_code', $gtin_code);
				$has_wcmp_spmv_map_id = get_post_meta($product-&gt;get_id(), '_wcmp_spmv_map_id', true);
				if ($has_wcmp_spmv_map_id) {
					$data = array('product_id' =&gt; $duplicate_product-&gt;get_id(), 'product_map_id' =&gt; $has_wcmp_spmv_map_id);
					update_post_meta($duplicate_product-&gt;get_id(), '_wcmp_spmv_map_id', $has_wcmp_spmv_map_id);
					wcmp_spmv_products_map($data, 'insert');
				} else {
					$data = array('product_id' =&gt; $duplicate_product-&gt;get_id());
					$map_id = wcmp_spmv_products_map($data, 'insert');

					if ($map_id) {
						update_post_meta($duplicate_product-&gt;get_id(), '_wcmp_spmv_map_id', $map_id);
						$data = array('product_id' =&gt; $product-&gt;get_id(), 'product_map_id' =&gt; $map_id);
						wcmp_spmv_products_map($data, 'insert');
						update_post_meta($product-&gt;get_id(), '_wcmp_spmv_map_id', $map_id);
					}
						update_post_meta($product-&gt;get_id(), '_wcmp_spmv_product', true);
				}
				update_post_meta($duplicate_product-&gt;get_id(), '_wcmp_spmv_product', true);
				// Add other post meta updates here like the example below where Yoast's setting is set to not index the duplicate product. There are a huge variety of other updates that could be applicable to your particular situation.
				// update_post_meta($duplicate_product-&gt;get_id(),'_yoast_wpseo_meta-robots-noindex', 1);
				$duplicate_product-&gt;save();
				// Uncomment this line below to remove featured product from duplicate
				// wp_remove_object_terms($duplicate_product-&gt;get_id(), 'featured', 'product_visibility');
			}
				$counter++;
		}
	}
	$redirect = add_query_arg( 'duplicate_product_to_vendor_done', $counter, $redirect );
	return $redirect;
}
</code></pre>



<p><em>Note:  All duplicates are initially created as a draft. After duplication, use bulk edit to assign the products to a vendor and change the status to &#8216;Published&#8217;.</em></p>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading">Synchronize Mapped Products</h2>



<p>Another SPMV (Single Product Multiple Vendor) issue I ran into while configuring a client&#8217;s site with WCMp was dealing with synchronizing product fields including featured image, stock, price, sale price, description, short description, and image gallery. In many cases, the vendor may not need to control products at all or may only need to control certain product details/fields. In the situation where you have multiple vendors selling the same products out of one inventory, this was extremely important. This code snippet will likely need to be customized for each specific site, but it provides a great base to work from and covers both simple and variable products.  It can be inserted into the (child) theme&#8217;s functions.php file or could potentially be used to create a standalone plugin. </p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">// Update mapped product fields after product update
add_action( 'woocommerce_update_product', 'woocommerce_update_mapped_product_sync', 10, 1 );
// Fields updated: featured image, stock, price, sale price, description, short description, image gallery
function woocommerce_update_mapped_product_sync( $product_get_id ) {
	global $wpdb;

	if(!user_can( get_post_field( 'post_author', $product_get_id ), 'administrator' )){
		return;
	}
	$has_product_map_id = get_post_meta($product_get_id, '_wcmp_spmv_map_id', true);

	if($has_product_map_id){
			$mapped_products = $wpdb-&gt;get_results( "select m.post_id as post_id, p.post_title as post_title, p.post_content as post_content, p.post_excerpt as post_excerpt from $wpdb-&gt;posts as p JOIN $wpdb-&gt;postmeta as m ON p.ID = m.post_id where m.meta_key = '_wcmp_spmv_map_id' AND m.meta_value = $has_product_map_id AND m.post_id &lt;&gt; $product_get_id", ARRAY_A );
			if($mapped_products){
				$product = wc_get_product( $product_get_id );
				$product_name = $product-&gt;get_name();
				$product_stock_count = $product-&gt;get_stock_quantity();
				$product_regular_price = $product-&gt;get_regular_price();
				$product_price = $product-&gt;get_price();
				$product_sale_price = $product-&gt;get_sale_price();
				$product_description = $product-&gt;get_description();
				$product_short_description = $product-&gt;get_short_description();
				$product_image_id = get_post_thumbnail_id($product_get_id);
				$product_image_gallery = get_post_meta( $product_get_id, '_product_image_gallery');

					// Only for variable products
					if( $product-&gt;is_type('variable') ){

						foreach ($mapped_products as $mapped_product){
								$map_product_id = $mapped_product['post_id'];
							if($product_name &amp;&amp; $product_name != $mapped_product['post_title']){
								$post_product_name = array('post_title' =&gt; $product_name);
								$where_product_name = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_product_name, $where_product_name);
							}
							if($product_description &amp;&amp; $product_description != $mapped_product['post_content']){
								$post_description = array('post_content' =&gt; $product_description);
								$where_description = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_description, $where_description);
							}
							if($product_short_description &amp;&amp; $product_description != $mapped_product['post_excerpt']){
								$post_short_description = array('post_excerpt' =&gt; $product_description);
								$where_short_description = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_short_description, $where_short_description);
							}
							if($product_image_id){
								update_post_meta( $map_product_id, '_thumbnail_id', $product_image_id );
							}
							if($product_image_gallery){
								update_post_meta( $map_product_id, '_product_image_gallery', implode($product_image_gallery) );
							}
						}

						foreach ( $product-&gt;get_children() as $variation_id ) {

							// print_r($variation_id);exit;
							$variation = wc_get_product( $variation_id );
							$variation_name = $variation-&gt;get_name();
							$variation_stock_count = $variation-&gt;get_stock_quantity();
							$variation_regular_price = $variation-&gt;get_regular_price();
							$variation_price = $variation-&gt;get_price();
							$variation_sale_price = $variation-&gt;get_sale_price();
							$variation_description = $variation-&gt;get_description();
							$variation_short_description = $variation-&gt;get_short_description();
							$variation_image_id = get_post_thumbnail_id($variation_id);
							$variation_image_gallery = get_post_meta( $variation_id, '_product_image_gallery');
							$variation_attributes = $variation-&gt;get_attributes();
							foreach ($mapped_products as $mapped_product){

								$map_variation_product_id = $mapped_product['post_id'];
								$variation = wc_get_product( $map_variation_product_id );

								foreach ( $variation-&gt;get_children() as $map_variation_id ) {
									$map_variation = wc_get_product($map_variation_id);
									if($variation_attributes == $map_variation-&gt;get_attributes()){
										if(isset($variation_stock_count)) {
											if($variation_stock_count &gt; 0){
												update_post_meta($map_variation_id, '_stock_status', 'instock');
											}else{
												update_post_meta($map_variation_id, '_stock_status', 'outofstock');
											}
											update_post_meta( $map_variation_id, '_stock', $variation_stock_count );
										}
										if($variation_regular_price){
											update_post_meta( $map_variation_id, '_regular_price', $variation_regular_price );
										}
										if($variation_sale_price){
											update_post_meta( $map_variation_id, '_sale_price', $variation_sale_price );
											update_post_meta( $map_variation_id, '_price', $variation_sale_price );
										}
										if (!$variation_sale_price){
											if(metadata_exists( 'post', $map_variation_id, '_sale_price' )){
												delete_post_meta($map_variation_id,'_sale_price');
											}
											update_post_meta( $map_variation_id, '_price', $variation_regular_price );
										}
										if($variation_image_id){
											update_post_meta( $map_variation_id, '_thumbnail_id', $variation_image_id );
										}
										wc_delete_product_transients( $map_variation_id ); // Clear/refresh the variation cache
									}
								}
    					}
    					// Clear/refresh the variable product cache
    					wc_delete_product_transients( $variation_id );
						}

					}else{

						foreach ($mapped_products as $mapped_product){
								$map_product_id = $mapped_product['post_id'];
							if($product_name &amp;&amp; $product_name != $mapped_product['post_title']){
								$post_product_name = array('post_title' =&gt; $product_name);
								$where_product_name = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_product_name, $where_product_name);
							}
							if($product_description &amp;&amp; $product_description != $mapped_product['post_content']){
								$post_description = array('post_content' =&gt; $product_description);
								$where_description = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_description, $where_description);
							}
							if($product_short_description &amp;&amp; $product_description != $mapped_product['post_excerpt']){
								$post_short_description = array('post_excerpt' =&gt; $product_description);
								$where_short_description = array('ID' =&gt; $map_product_id);
								$wpdb-&gt;update("{$wpdb-&gt;prefix}posts", $post_short_description, $where_short_description);
							}
							if($product_image_id){
								update_post_meta( $map_product_id, '_thumbnail_id', $product_image_id );
							}
							if($product_image_gallery){
								update_post_meta( $map_product_id, '_product_image_gallery', implode($product_image_gallery));
							}
							if(isset($product_stock_count)) {
								if($product_stock_count &gt; 0){
									update_post_meta($map_product_id, '_stock_status', 'instock');
								}else{
									update_post_meta($map_product_id, '_stock_status', 'outofstock');
								}
								update_post_meta( $map_product_id, '_stock', $product_stock_count );
							}
							if($product_regular_price){
								update_post_meta( $map_product_id, '_regular_price', $product_regular_price );
							}
							if($product_sale_price){
								update_post_meta( $map_product_id, '_sale_price', $product_sale_price );
								update_post_meta( $map_product_id, '_price', $product_sale_price );
							}
							if(!$product_sale_price){
								if(metadata_exists( 'post', $map_product_id, '_sale_price' )){
									delete_post_meta($map_product_id,'_sale_price');
								}
								update_post_meta( $map_product_id, '_price', $product_regular_price );
							}
						}
					}
				}
			}
}</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading">Synchronize Stock on Mapped Products after Checkout Completed</h2>



<p>Similar to the code snippet above synchronizing fields on product update, this code snipped synchronizes only stock for all mapped product when a checkout is complete. It removes the quantity purchased from the stock of all the other mapped products. It is ONLY useful in SPMV (Single Product Multiple Vendor) scenarios where there is one master inventory. For example, a site administrator has all the inventory at their location and the vendors/shop owners simply list products for sale from that inventory. It is a unique circumstance, but I ran into it so maybe someone else will too. It can be inserted into the (child) theme&#8217;s functions.php file or could potentially be used to create a standalone plugin. </p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">add_action('woocommerce_thankyou', 'update_inventory_mapped_products', 10, 1);
function update_inventory_mapped_products( $order_id ) {

    if ( ! $order_id )
        return;

				//declare global objects
				global $WCMp, $wpdb;

    // Getting an instance of the order object
    $order = wc_get_order( $order_id );

    if(!$order-&gt;is_paid())
        return;

    // iterating through each order item (getting product ID)
    foreach ( $order-&gt;get_items() as $item_id =&gt; $item ) {

        if( $item['variation_id'] &gt; 0 ){
						$product_id = $item['product_id'];
            $variation_id = $item['variation_id']; // variable product
						$variation_excerpt = get_the_excerpt($variation_id);
						$has_product_map_id = get_post_meta($product_id, '_wcmp_spmv_map_id', true);
						$product_manage_stock = get_post_meta($variation_id, '_manage_stock', true);

						if($has_product_map_id &amp;&amp; $product_manage_stock == 'yes'){
								$product_stock_count = get_post_meta($variation_id, '_stock', true);

								$mapped_products = $wpdb-&gt;get_results( "select post_id from $wpdb-&gt;postmeta where meta_key = '_wcmp_spmv_map_id' AND meta_value = $has_product_map_id AND post_id &lt;&gt; $product_id", ARRAY_A );
								if($mapped_products){
									foreach ($mapped_products as $mapped_product){
										$mapped_product_product = wc_get_product($mapped_product['post_id']);
										if($mapped_product_product){
										// foreach( $mapped_product_product-&gt;get_available_variations() as $variation_values ){
										foreach ( $mapped_product_product-&gt;get_children() as $map_variation_product_id ) {
											// print_r($variation_values);
												// $map_variation_product_id = $variation_values['variation_id'];
												if($variation_excerpt == get_the_excerpt($map_variation_product_id)) {
														if($product_stock_count &gt; 0){
															update_post_meta($map_variation_product_id, '_stock_status', 'instock');
														}else{
															update_post_meta($map_variation_product_id, '_stock_status', 'outofstock');
														}
														update_post_meta( $map_variation_product_id, '_stock', $product_stock_count );
												}
											}
										}
									}
								}
						}
        } else {
            $product_id = $item['product_id']; // simple product
						$has_product_map_id = get_post_meta($product_id, '_wcmp_spmv_map_id', true);
						$product_manage_stock = get_post_meta($product_id, '_manage_stock', true);

						if($has_product_map_id &amp;&amp; $product_manage_stock == 'yes'){
								$product_stock_count = get_post_meta($product_id, '_stock', true);

								$mapped_products = $wpdb-&gt;get_results( "select post_id from $wpdb-&gt;postmeta where meta_key = '_wcmp_spmv_map_id' AND meta_value = $has_product_map_id AND post_id &lt;&gt; $product_id", ARRAY_A );

								if($mapped_products){
									foreach ($mapped_products as $mapped_product){
										// update_post_meta( $mapped_product['post_id'], '_stock', $product_stock_count );
										if($product_stock_count &gt; 0){
											update_post_meta($mapped_product['post_id'], '_stock_status', 'instock');
										}else{
											update_post_meta($mapped_product['post_id'], '_stock_status', 'outofstock');
										}
										update_post_meta($mapped_product['post_id'], '_stock', $product_stock_count );
									}
								}

						}
        }
    }
}</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<h2 class="wp-block-heading">Disable WCMp Visitor Stats</h2>



<p>This is a simple code snippet. It can be found on WCMp&#8217;s site as well, but it&#8217;s an important one to me! Plugin-based visitor tracking can decrease site performance.  Collecting visitor stats in the WordPress database can also eventually cause more performance problems due to a bloated database. Even though it may be a nice stat to show vendors on their dashboard, stick with 3rd party analytics like Google Analytics, Jetpack Site Stats, or another provider to track stats unless you have a very low traffic website.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">// Remove visitor stats tracking
add_filter('wcmp_is_disable_store_visitors_stats', '__return_false');</code></pre>



<hr class="wp-block-separator has-css-opacity"/>



<p>Leave your ideas, requests, or feedback on these code snippets below in the comments. Thanks!</p>
<p>The post <a href="https://highlyresponsive.com/multivendorx-code-snippets/">How To Customize WCMp (now MultivendorX) With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://highlyresponsive.com/multivendorx-code-snippets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How To Customize OceanWP Theme With Code Snippets</title>
		<link>https://highlyresponsive.com/oceanwp-code-snippets/</link>
					<comments>https://highlyresponsive.com/oceanwp-code-snippets/#respond</comments>
		
		<dc:creator><![CDATA[hradmin]]></dc:creator>
		<pubDate>Fri, 28 Feb 2020 22:16:38 +0000</pubDate>
				<category><![CDATA[Code Snippets]]></category>
		<guid isPermaLink="false">https://highlyresponsive.com/?p=3169</guid>

					<description><![CDATA[<p>This is a small collection of code snippets to customize the OceanWP theme and associated features. I&#8217;ve only used OceanWP on a few sites now and it is clearly a very powerful, customizable theme but there are still features not ... </p>
<p class="read-more-container"><a title="How To Customize OceanWP Theme With Code Snippets" class="read-more button" href="https://highlyresponsive.com/oceanwp-code-snippets/#more-3169" aria-label="Read more about How To Customize OceanWP Theme With Code Snippets">Read More</a></p>
<p>The post <a href="https://highlyresponsive.com/oceanwp-code-snippets/">How To Customize OceanWP Theme With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This is a small collection of code snippets to customize the OceanWP theme and associated features. I&#8217;ve only used OceanWP on a few sites now and it is clearly a very powerful, customizable theme but there are still features not available without adding a few code snippets to your (child) theme&#8217;s functions.php file. </p>



<p>If you&#8217;re not comfortable with OceanWP yet, surf on over to the official <a href="https://docs.woocommerce.com/wc-apidocs/hook-docs.html" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">OceanWP Documentation</a> where you can find extensive documentation of the OceanWP hooks and filters as well as some simple help articles. </p>



<p class="has-small-font-size"><strong>IMPORTANT NOTE : Never forget to disable features you&#8217;re not using with OceanWP under the Theme Panel -&gt; Scripts &amp; Styles. It can make a huge difference in PageSpeed scores and page load times even when using optimal cache settings.</strong></p>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Set Featured Image as OceanWP Page Title Background Image</h2>



<p>There are plenty of snippets out there for this hook &#8211; ocean_page_header_background_image &#8211; but I never found one that set the featured image for a post, page, or product as the background image automatically. So here it is! You obviously have to select &#8216;Background Image&#8217; as the &#8216;Page Title&#8217; style inside the Customizer settings for the OceanWP theme in order for this code to be effective. The code snippet should be inserted into the (child) theme&#8217;s functions.php file. </p>



<pre class="wp-block-code"><code lang="php" class="language-php line-numbers">/* Set your single page, post, or product header background image to the featured image for that page, post, or product */
function my_oceanwp_header_bg_img( $bg_img ) {

        /* Detect if it's an individual product, post, or page. You can add or remove post types inside the if statement to customize display conditions */
	if ( is_singular( 'product' ) || is_singular( 'post') || is_singular( 'page' ) {
		$featured_id = get_post_thumbnail_id();
                // Don't forget to specify the thumbnail size you want to use, in this case I used 'large'
		$featured_url_array = wp_get_attachment_image_src($featured_id, 'large', true);
		$bg_img = $featured_url_array[0];
	}

	return $bg_img;

}
add_filter( 'ocean_page_header_background_image', 'my_oceanwp_header_bg_img' );</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Set Custom Page Title and Subheading in OceanWP (specifically for WooCommerce shop)</h2>



<p>This code snippet is nothing special, but it shows you how you can change the WooCommerce shop page title and subheading since it can&#8217;t be changed without a little extra code. You could also use this same code snippet to change the page title or subheading on any post, page, custom post type, etc. by placing the appropriate detection in the if() statement. This is especially useful for automatically built-in pages like the Shop page that is automatically generated by WooCommerce. This code should be place in the (child) theme&#8217;s functions.php file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Change Page Title on WooCommerce Shop Page */
function my_change_page_header_title( $title ) {
    if ( is_shop() ) {
        $title = 'My Custom Shop Title';
    }
    return $title;
}
add_filter( 'ocean_title', 'my_change_page_header_title', 20 );

/* Change the WooCommerce Shop page subheading */
function my_change_page_header_subheading( $subheading ) {
    if ( is_shop() ) {
        $subheading = 'Subheading for my shop';
    }
    return $subheading;
}
add_filter( 'ocean_post_subheading', 'my_change_page_header_subheading' );</code></pre>



<hr class="wp-block-separator"/>



<h2 class="wp-block-heading">Show Custom OceanWP Sidebar on Specific (WooCommerce) Pages</h2>



<p>OceanWP allows you to create custom sidebars. To programmatically set where they appear, add the following code snippet and alter it to your liking. The code snippet below specifically sets a sidebar filled with FacetWP facets to appear on the WooCommerce shop page and all product category pages so site visitors can always filter down the products with that sidebar showing. You can alter the if() statement to detect the page(s) that you want a custom sidebar to show on &#8211; for example, is_singular( &#8216;gallery&#8217; ) or is_singular( &#8216;product&#8217; ) or is_page( &#8216;page-slug&#8217; ). Obviously don&#8217;t forget to change the custom sidebar id to your own custom sidebar. Place this code snippet in the OceanWP (child) theme&#8217;s functions.php file.</p>



<pre class="wp-block-code"><code lang="php" class="language-php">/* Custom sidebar for product archives and shop pages */
function woo_custom_sidebar_display( $sidebar ) {
 if ( is_woocommerce() &amp;&amp; ( is_product_taxonomy() || is_shop() )) {
        // OceanWP custom sidebar created
	return 'ocs-product-listings';
 }	
 else {
       // Return theme defined sidebar area
       return $sidebar;
 }
}
add_filter( 'ocean_get_sidebar', 'woo_custom_sidebar_display' );</code></pre>



<hr class="wp-block-separator"/>



<p>Leave your ideas, requests, or feedback on these code snippets below in the comments. Thanks!</p>
<p>The post <a href="https://highlyresponsive.com/oceanwp-code-snippets/">How To Customize OceanWP Theme With Code Snippets</a> appeared first on <a href="https://highlyresponsive.com">Highly Responsive</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://highlyresponsive.com/oceanwp-code-snippets/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
