Skip to content

Instantly share code, notes, and snippets.

View alexdeborba's full-sized avatar
:octocat:
DevOps

Alex de Borba alexdeborba

:octocat:
DevOps
View GitHub Profile
// Allow wholesale customers to view all products
function allow_wholesale_customer_view_all_products($query) {
// Check if the user has the "wholesale_customer" role and if it's the main query
if (current_user_can('wholesale_customer') && $query->is_main_query()) {
// Set the query to retrieve products only
$query->set('post_type', 'product');
// Set the post status to include both published and private products
$query->set('post_status', ['publish', 'private']);
// Ignore sticky posts
$query->set('ignore_sticky_posts', true);
@alexdeborba
alexdeborba / gist:1dca47ee02bac23a20f8c2afe0409348
Created July 25, 2023 22:37
Disable Jetpack modules except WooCommerce App
add_filter( 'jetpack_get_default_modules', 'disable_all_jetpack_modules_except_woocommerce' );
function disable_all_jetpack_modules_except_woocommerce( $modules ) {
// List of Jetpack modules needed for WooCommerce App.
$required_modules = array(
'json-api', // Required for the WooCommerce Mobile App.
// Add other modules as needed.
);
// Disable all modules except those in the list above.
@alexdeborba
alexdeborba / gist:d7a24b1ea9bb5ee16dde5392bec6e722
Created June 14, 2023 18:49
WooCommerce: Hide Price if Value is 0
// Add this code to your child theme's functions.php file
add_filter( 'woocommerce_get_price_html', 'hide_zero_price', 10, 2 );
/**
* Hide price if it is zero
*
* @param string $price The price (HTML formatted).
* @param WC_Product $product The product object.
* @return string
@alexdeborba
alexdeborba / gist:14389d06fd060a8d53f0af861a8e4cdf
Created June 8, 2023 12:53
WooCommerce: Action to limit User Role to a number items per Order
// Add an action on cart evaluation
add_action( 'woocommerce_check_cart_items', 'limit_cart_items_for_specific_role' );
function limit_cart_items_for_specific_role() {
// The user role to check against
$user_role_to_check = 'subscriber';
// The item limit
$item_limit = 3;
// Get the current user
@alexdeborba
alexdeborba / gist:72e0de0db7312d848432eeb396504539
Created June 8, 2023 11:42
Function to Disable Free Orders Completed Email
/**
* This function checks if an order has a total of zero (free), and if so, stops the "Completed order" email from being sent.
*
* @param bool $is_enabled - Original state of the email (enabled/disabled)
* @param WC_Order $order - The order object for which the email is being sent
* @return bool - Modified state of the email (enabled/disabled)
*/
function disable_free_order_completed_email( $is_enabled, $order ) {
// Check if the order total is zero
if ( 0 == $order->get_total() ) {
@alexdeborba
alexdeborba / gist:167a09d7e766cc1621d01b47b348139b
Last active June 8, 2023 11:36
Action to show on Single Product only Related Products to Product Archive
// Remove default related products function
remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
// Add our custom related products function to the same hook
add_action( 'woocommerce_after_single_product_summary', 'custom_related_products', 20 );
function custom_related_products() {
// Use global $product object
global $product;
// Prepare the arguments for WP_Query
<style>
.staffer img {
clear: both;
display: block;
margin: 0 auto;
-webkit-mask-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNjAwIDYwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNDU0LjUgMTM3LjZDNTIwIDIwMC4xIDU5OC4yIDI2OC41IDYwMCAzNDMuOGMxLjYgNzUuMy03My40IDE1Ny41LTE3MS40IDIwNy41LTk4IDQ5LjktMjE4LjkgNjcuOC0yOTcgMjMuMi03Ny45LTQ0LjQtMTEyLjgtMTUxLjEtMTI2LTI1MFMuOSAxMzQuNyA1MSA3NS42YzQ5LjktNTkuMSAxNDEuMy04Ni40IDIxMy4zLTcxLjdDMzM2LjMgMTguNiAzODkgNzUgNDU0LjUgMTM3LjZ6Ii8+PC9zdmc+);
mask-image: url(data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNjAwIDYwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNNDU0LjUgMTM3LjZDNTIwIDIwMC4xIDU5OC4yIDI2OC41IDYwMCAzNDMuOGMxLjYgNzUuMy03My40IDE1Ny41LTE3MS40IDIwNy41LTk4IDQ5LjktMjE4LjkgNjcuOC0yOTcgMjMuMi03Ny45LTQ0LjQtMTEyLjgtMTUxLjEtMTI2LTI1MFMuOSAxMzQuNyA1MSA3NS42YzQ5LjktNTkuMSAxNDEuMy04Ni40IDIxMy4zLTcxLjdDMzM2LjMgMTguNiAzODkgNzUgNDU0LjUgMTM3LjZ6Ii8+PC9zdmc+);
}
</style>
// Function to add Custom Post Type.
function olympus_custom_post_type()
{
// Register the doc post type
register_post_type( 'docs', array(
'labels' => array(
'name' => esc_html__( 'Documentation', 'olympus' ),
'singular_name' => esc_html__( 'Document', 'olympus' ),
'add_new' => esc_html__( 'Add New', 'olympus' ),
Fatal error: Uncaught Error: Unknown named parameter $form in /www/aeon_689/public/wp-content/plugins/gravityforms/includes/addon/class-gf-addon.php:829 Stack trace: #0 /www/aeon_689/public/wp-includes/class-wp-hook.php(285): GFAddOn->enqueue_scripts() #1 /www/aeon_689/public/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #2 /www/aeon_689/public/wp-includes/plugin.php(484): WP_Hook->do_action(Array) #3 /www/aeon_689/public/wp-admin/admin-header.php(102): do_action('admin_enqueue_s...', 'toplevel_page_g...') #4 /www/aeon_689/public/wp-admin/admin.php(239): require_once('/www/aeon_689/p...') #5 {main} thrown in /www/aeon_689/public/wp-content/plugins/gravityforms/includes/addon/class-gf-addon.php on line 829
if(
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
die;
}