This file contains 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
<?php | |
// Find the description at https://bloggerpilot.com/en/gutenberg-for-woocommerce/ | |
// Disable new WooCommerce product template (from Version 7.7.0) | |
function bp_reset_product_template($post_type_args) { | |
if (array_key_exists('template', $post_type_args)) { | |
unset($post_type_args['template']); | |
} | |
return $post_type_args; | |
} |
This file contains 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
<?php | |
/** | |
* Check if a specific product category is in the cart | |
*/ | |
function wc_ninja_category_is_in_the_cart() { | |
// Add your special category slugs here | |
$categories = array( 'clothing', 'posters' ); | |
// Products currently in the cart | |
$cart_ids = array(); |
This file contains 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
<?php | |
/** | |
* Conditionally remove a checkout field based on products in the cart | |
*/ | |
function wc_ninja_remove_checkout_field( $fields ) { | |
if ( ! wc_ninja_product_is_in_the_cart() ) { | |
unset( $fields['billing']['billing_company'] ); | |
} | |
return $fields; |
This file contains 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
<?php | |
/** | |
* Check if a specific product ID is in the cart | |
*/ | |
function wc_ninja_product_is_in_the_cart() { | |
// Add your special product IDs here | |
$ids = array( '45', '70', '75' );; | |
// Products currently in the cart | |
$cart_ids = array(); |
This file contains 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
<?php // Do not include this if already open! Code goes in theme functions.php. | |
/** | |
* Add fields to the checkout page based on products in cart. | |
* | |
* @how-to https://remicorson.com/?p=7871 | |
* @author Remi Corson | |
* @testedwith WooCommerce 3.4.0 | |
*/ |
This file contains 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
/** | |
* is_type can be simple, variable, grouped, external | |
* woocommerce_single_product_summary is hook! | |
* Put this into your functions.php (child-theme) | |
**/ | |
add_action( 'woocommerce_single_product_summary', 'get_product_type', 5 ); | |
function get_product_type() { | |
global $post; | |
if( function_exists('get_product') ){ | |
$product = get_product( $post->ID ); |
This file contains 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
var waitForEl = function(selector, callback) { | |
if (jQuery(selector).length) { | |
callback(); | |
} else { | |
setTimeout(function() { | |
waitForEl(selector, callback); | |
}, 100); | |
} | |
}; |