Created
April 10, 2024 14:24
-
-
Save contemplate/7dd17d14b53ca1fa68702cebee4edb60 to your computer and use it in GitHub Desktop.
WPC Product Bundles for WooCommerce Shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hook into init action to set bundled_position to "no" if the shortcode is used | |
function wpc_set_bundled_position() { | |
add_filter('woosb_get_setting', 'wpc_disable_bundled_position', 10, 3); | |
} | |
// Function to set bundled_position to "no" if the shortcode is used | |
function wpc_disable_bundled_position($setting, $name, $default) { | |
// Check if the shortcode is used on the current page | |
if ($name === 'bundled_position' && wpc_is_show_bundled_shortcode_used()) { | |
return 'no'; | |
} | |
return $setting; | |
} | |
// Function to check if the wpc_show_bundled shortcode is used on the current page | |
function wpc_is_show_bundled_shortcode_used() { | |
global $post; | |
// Check if the shortcode is present in the post content or product short description | |
$post_content_has_shortcode = has_shortcode($post->post_content, 'wpc_show_bundled'); | |
$product_description_has_shortcode = has_shortcode($post->post_excerpt, 'wpc_show_bundled'); | |
return $post_content_has_shortcode || $product_description_has_shortcode; | |
} | |
// Custom shortcode function | |
function wpc_show_bundled_shortcode() { | |
// Fire the show_bundled function | |
if (function_exists('WPCleverWoosb')) { | |
WPCleverWoosb()->show_bundled(); | |
} | |
} | |
// Register the shortcode and hook into init action | |
add_shortcode('wpc_show_bundled', 'wpc_show_bundled_shortcode'); | |
add_action('init', 'wpc_set_bundled_position'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use with this plugin: https://wordpress.org/plugins/woo-product-bundle/
Place the [wpc_show_bundled] shortcode in the product description or short description to show the bundled products and it will be removed from the default placement defined in the plugin settings.