Skip to content

Instantly share code, notes, and snippets.

Gareth Harris plugin-republic

Block or report user

Report or block plugin-republic

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View wcfad_exclude_from_role_based_rules.php
<?php
// Exclude some products from global role-based rules
function wcfad_exclude_from_role_based_rules( $excluded ) {
return $excluded;
return array( 15, 119 );
}
add_filter( 'wcfad_exclude_from_role_based_rules', 'wcfad_exclude_from_role_based_rules' );
View pewc_filter_validate_cart_item_status.php
<?php
/**
* Validate a text string to check first character is a letter and 2nd to 7th characters are numeric
*/
function prefix_filter_validate_text_string( $passed, $post, $item ) {
// Change the field ID as necessary
if( isset( $item['field_id'] ) && $item['field_id'] == 4904 ) {
$string = $post[$item['id']];
$first_letter = substr( $string, 0, 1 );
View pewc_product_show_totals.php
<?php
function demo_pewc_product_show_totals( $show_totals, $post_id ) {
// Show the Totals fields for product IDs in the array
$totals = array( 64, 66, 454 );
if( in_array( $post_id, $totals ) ) {
$show_totals = 'total';
}
// Hide the Totals fields for product IDs in this array
if( in_array( $post_id, array( 969, 1111 ) ) ) {
View pewc_show_option_prices_in_cart.php
<?php
/**
* Hide option prices in the cart
*/
add_filter( 'pewc_show_option_prices_in_cart', '__return_false' );
View woocommerce_order_status_completed.php
<?php
/**
* Assign roles when status is set to completed
*/
add_action( 'woocommerce_order_status_completed', 'wcmo_assign_roles_after_purchase', 10 );
View tester_remove_fields_from_before_button.php
<?php
/**
* Move add-on fields below the add to cart button
*/
function tester_remove_fields_from_before_button() {
remove_action( 'woocommerce_before_add_to_cart_button', 'pewc_product_extra_fields' );
add_action( 'woocommerce_after_add_to_cart_button', 'pewc_product_extra_fields' );
}
add_action( 'init', 'tester_remove_fields_from_before_button' );
View pewc_hidden_field_types_in_cart.php
<?php
/**
* Hide certain field types in the cart and checkout
*/
function tester_hidden_field_types_in_cart( $field_types ) {
$field_types = array( 'calculation', 'number' );
return $field_types;
}
add_filter( 'pewc_hidden_field_types_in_cart', 'tester_hidden_field_types_in_cart' );
View pewc_disable_pricing.php
<?php
remove_action( 'woocommerce_before_calculate_totals', 'pewc_wc_calculate_total', 10, 1 );
remove_filter( 'woocommerce_cart_item_price', 'pewc_minicart_item_price', 10, 3 );
remove_action( 'woocommerce_cart_calculate_fees', 'pewc_cart_calculate_fees', 10 );
function prefix_remove_actions() {
remove_action( 'woocommerce_before_calculate_totals', 'pewc_wc_calculate_total', 10, 1 );
remove_filter( 'woocommerce_cart_item_price', 'pewc_minicart_item_price', 10, 3 );
remove_action( 'woocommerce_cart_calculate_fees', 'pewc_cart_calculate_fees', 10 );
}
View pewc_calculation_global_calculation_vars.php
<?php
/**
* Create multiple variables for calculation fields
*/
function prefix_calculation_global_calculation_vars( $vars ) {
return array(
'my_first_variable' => 50,
'price_modifier_1' => 150
);
}
View pewc_filter_validate_cart_item_status.php
<?php
/**
* Custom validation for add-on fields
*/
function prefix_filter_validate_cart_item_status( $passed, $post, $item ) {
// pewc_group_3990_4033 is the ID of the field
if( isset( $post['pewc_group_3990_4033'] ) && floatval( $post['pewc_group_3990_4033'] ) < 10 ) {
wc_add_notice( 'My validation message', 'error' );
$passed = false;
}
You can’t perform that action at this time.