Skip to content

Instantly share code, notes, and snippets.

View lucasstark's full-sized avatar

Lucas Stark lucasstark

View GitHub Profile
add_filter( 'wc_dynamic_pricing_get_product_pricing_rule_sets', 'custom_wc_dynamic_pricing_get_product_pricing_rule_sets', 10, 3 );
function custom_wc_dynamic_pricing_get_product_pricing_rule_sets( $rulesets, $product_id, $pricing_module ) {
$custom_rule_set = array(
'conditions_type' => 'all',
'conditions' => array(
1 => array(
'type' => 'apply_to',
'args' => array(
add_filter('woocommerce_catalog_restrictions_get_roles_for_current_user', 'custom_woocommerce_catalog_restrictions_get_roles_for_current_user');
function custom_woocommerce_catalog_restrictions_get_roles_for_current_user($roles){
if ( current_user_can( 'wholesale_user')) {
unset($roles['guest']);
}
return $roles;
}
add_filter('woocommerce_catalog_restrictions_get_roles_for_current_user', 'custom_woocommerce_catalog_restrictions_get_roles_for_current_user');
function custom_woocommerce_catalog_restrictions_get_roles_for_current_user($roles){
if ( !current_user_can( 'wholesale_user')) {
$roles['customer'] = 'customer';
}
return $roles;
}
add_filter('wc_dynamic_pricing_price_html', 'custom_wc_dynamic_pricing_price_html', 10, 2);
function custom_wc_dynamic_pricing_price_html($html, $product){
$html = $html . $product->get_price_suffix();
return $html;
}
add_filter('woocommerce_dynamic_pricing_is_rule_set_valid_for_user', 'allow_guest_for_rules', 10, 3);
function allow_guest_for_rules( $result, $condition, $adjustment_set ) {
if ( $condition['args']['applies_to'] == 'roles' && isset( $condition['args']['roles'] ) && is_array( $condition['args']['roles'] ) ) {
foreach ( $condition['args']['roles'] as $role ) {
if ( ( $role == 'guest' && !is_user_logged_in() ) || current_user_can( $role ) ) {
$result = 1;
break;
}
}
add_filter('woocommerce_get_availability', 'custom_woocommerce_get_availability', 10, 2);
function custom_woocommerce_get_availability($avail, $product) {
global $post;
$old_post = $post;
$post = get_post($product->variation_id);
$result = WC_Conditional_Content_Display::instance()->template_display(0, false);
$post = $old_post;
if ($result){
$exists = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type = %s AND post_status = %s AND ID = %d", 'you-post-type', 'publish', $your_post_id));
if (!empty($exists) && !is_wp_error( $exists )){
//post exists.
}
/*---------------------------------------------------------------------------------------------
*
* Postbox: Fields
*
*---------------------------------------------------------------------------------------------*/
#acf-field-group-fields > .inside {
padding: 0;
margin: 0;
}
#acf-field-group-fields > .handlediv,
@lucasstark
lucasstark / gist:3ef57f8b8e98ac69d39c
Created May 12, 2015 16:00
Dynamic Pricing - Exclude Sale Items
add_filter('woocommerce_dynamic_pricing_process_product_discounts', 'wcdp_exclude_sale_items', 10, 2);
function wcdp_exclude_sale_items( $include, $product ) {
$instance = WC_Dynamic_Pricing::instance();
remove_filter( 'woocommerce_get_price', array($instance, 'on_get_price'), 10, 2 );
remove_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'wcdp_exclude_sale_items', 10, 2 );
if ( $product->is_on_sale() ) {
$include = false;
}
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'wcdp_exclude_sale_items', 10, 2 );
add_filter( 'woocommerce_dynamic_pricing_process_product_discounts', 'disable_bundles_from_dynamic_pricing', 99, 5 );
function disable_bundles_from_dynamic_pricing( $process, $product, $module_name, $module, $cart_item ) {
if ( is_array( $cart_item ) && isset( $cart_item['bundled_by'] ) && !empty($cart_item['bundled_by']) ) {
return false;
} else {
return $process;
}
}