Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Update cart item notes
*/
function prefix_update_cart_notes() {
// Do a nonce check
if( ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'woocommerce-cart' ) ) {
wp_send_json( array( 'nonce_fail' => 1 ) );
exit;
}
<?php
/**
* Get the user's roles
* @since 1.0.0
*/
function wcmo_get_current_user_roles() {
if( is_user_logged_in() ) {
$user = wp_get_current_user();
$roles = ( array ) $user->roles;
return $roles; // This returns an array
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule ^(.*)$ "https\:\/\/newdomain\.com\/$1" [R=301,L]
function bv_wc_ajax_variation_threshold( $qty, $product ) {
return 50;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'bv_wc_ajax_variation_threshold', 10, 2 );
@plugin-republic
plugin-republic / pewc-order-meta.php
Last active November 21, 2019 07:01
Iterate through product extras meta in order
<?php
function pewc_check_order_meta( $product_name, $item ) {
if( isset( $item['product_extras']['groups'] ) ) {
foreach ( $item['product_extras']['groups'] as $groups ) {
if( $groups ) {
$product_name .= '<ul>';
foreach( $groups as $group ) {
if( isset( $group['type'] ) ) {
// if( isset( $group['type'] ) && empty( $group['flat_rate'] ) ) {
$classes = array( strtolower( str_replace( ' ', '_', $group['type'] ) ) );
<?php
// Replace HTTP with HTTPS in arrow resource
function prefix_filter_cart_remove_linked_product( $arrow_right, $cart_item_key ) {
return str_replace( 'http://', 'https://', $arrow_right );
}
add_filter( 'pewc_filter_cart_remove_linked_product', 'prefix_filter_cart_remove_linked_product', 10, 2 );
<?php
/**
* @param $multiple '' | 'multiple'
* @param $product_id Product ID
* @param $id Field ID
*/
// Enable multiple uploads for all file inputs
function prefix_filter_multiple( $multiple, $product_id, $id ) {
return 'multiple';
<?php
// Allow zero cost bookings
add_filter( 'bfwc_allow_zero_cost_bookings', '__return_true' );
<?php
/**
* Filter flat rate fields to ensure that the same flat rate field can get charged for multiple products
*/
function prefix_filter_flat_rate( $label, $id, $flat_rate ) {
$label .= $id;
return $label;
}
add_filter( 'pewc_flat_rate_label', 'prefix_filter_flat_rate', 10, 3 );
@plugin-republic
plugin-republic / text.php
Created May 24, 2019 08:45
Display a text add-on in a table
<?php
/**
* A text field template
* @since 2.0.0
* @package WooCommerce Product Add-Ons Ultimate
* @see https://pluginrepublic.com/documentation/overriding-templates/ for more details
*/
// Exit if accessed directly
if( ! defined( 'ABSPATH' ) ) {