Skip to content

Instantly share code, notes, and snippets.

<?php
/**
* Ensure that products with user ID permissions override any global settings
*/
add_filter( 'wcmo_always_show_user_products', '__return_true' );
<?php
function pewc_ajax_add_child_product_to_cart() {
$result = WC()->cart->add_to_cart( intval( $_POST['product_id'] ), intval( $_POST['quantity'] ) );
$result ? wp_send_json_success() : wp_send_json_error();
}
add_action('wp_ajax_pewc_add_child_product_to_cart', 'pewc_ajax_add_child_product_to_cart');
add_action('wp_ajax_nopriv_pewc_add_child_product_to_cart', 'pewc_ajax_add_child_product_to_cart');
<?php
/**
* Automatically populate a field with user data
* Enter the user field in the 'Default' field
* Wrapped in {}
* E.g. {first_name}
*/
function junhee_populate_user_field( $value, $id, $item, $posted ) {
if( is_user_logged_in() ) {
<?php
function prefix_external_registration_approval_message( $message, $url, $user_id ) {
if( ! apply_filters( 'wcmo_allow_external_approval', false ) ) {
return $message;
}
$user_data = get_userdata( $user_id );
$message .= '<p>User email: ' . $user_data->user_email . '</p>';
return $message;
<?php
add_filter( 'wcmo_allow_external_approval', '__return_true' );
<?php
/**
* Get the user's location and populate the address
*/
function prefix_created_customer( $user_id ) {
// Lcoation field ID
$field_id = '4171f87f';
// Get the location
<?php
/**
* Apply the standard booking cost as a fixed cost to a booking, regardless of how long the booking is
*/
function prefix_fixed_booking_cost( $booking_cost, $product_id ) {
$product = wc_get_product( $product_id );
$booking_cost = floatval( bfwc_get_standard_cost( $product ) );
return $booking_cost;
<?php
function demo_close_accordion() {
return 'yes';
}
add_filter( 'pewc_close_accordion', 'demo_close_accordion' );
@plugin-republic
plugin-republic / pr_query_attachments.php
Created April 29, 2024 08:43
Query WordPress attachments with no alt text and automatically create alt text using file name
<?php
/**
* Query WordPress attachments with no alt text
* Automatically create alt text using file name
* Remove this snippet once you've run it
*/
function pr_query_attachments() {
if( did_action( 'init' ) > 1 ) {
return;
}
<?php
/**
* Remove quantity input field in cart for specific products
*/
function prefix_cart_item_quantity( $product_quantity, $cart_item_key ){
$cart_item = WC()->cart->cart_contents[ $cart_item_key ];
$product_id = $cart_item['data']->get_id();
if( in_array( $product_id, array( 467, 789 ) ) ){
$product_quantity = $cart_item['quantity'];
}