Skip to content

Instantly share code, notes, and snippets.

@Acephalia
Acephalia / wcsmboq.php
Created January 20, 2024 05:25
Woocommerce Disable/Enable Shipping Methods based on the number of products in the cart
// Disable/Enable Shipping Methods based on the number of products in the cart by u/acephaliax
add_filter( 'woocommerce_package_rates', 'conditionally_enable_shipping_methods', 10, 2 );
function conditionally_enable_shipping_methods( $rates, $package ) {
$cart_items_count = WC()->cart->get_cart_contents_count();
// Instance IDs to adjust (replace with your actual IDs)
$method_id_to_disable_for_large_carts = 9;
$method_id_to_enable_for_large_carts = 10;
@Acephalia
Acephalia / amptc.wc
Last active January 9, 2024 23:42
Shortcode To Add Multiple Products To Cart
//Start Shop The Look Shortcode by u/acephaliax
function shop_the_look_button_shortcode($atts) {
// Shortcode attributes
$atts = shortcode_atts(
array(
'ids' => '', // Product IDs comma-separated
),
$atts,
'shop_the_look'
);
@Acephalia
Acephalia / masrde.md
Last active January 9, 2024 06:04
Mac OSX Remove Disabled Extensions

Disclaimer: Before proceeding, be aware that modifying system files can potentially cause issues if done incorrectly. Follow the instructions carefully, and ensure you have a backup or recovery plan in case of any unintended consequences. This works on all silicone devices and the latest OS.

Open a terminal window:

cd /var/db/SystemPolicyConfiguration sudo sqlite3 KextPolicy

You'll see a sqlite> prompt. Type:

.tables

@Acephalia
Acephalia / wpdicfval.js
Last active December 21, 2023 22:22
Divi Contact Form Field URL Validation
<script>
jQuery(document).ready(function($) {
// Get the form field. Change #et_pb_contact_url_0 to match your target field
var urlField = $('#et_pb_contact_url_0');
var form = $('form');
// Regular expression to validate URLs
var urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;
// Flag to track validation status
@Acephalia
Acephalia / wprhfaufo.php
Last active December 14, 2023 22:36
Remove/replace "https://" from ACF URL field output
// Remove "https://" from ACF URL field output
function sanitize_acf_url_output($value, $post_id, $field) {
if ($field['type'] === 'url') {
// Remove "https://" from the URL
$value = str_replace('https://', '', $value);
}
return $value;
}
add_filter('acf/format_value/type=url', 'sanitize_acf_url_output', 10, 3);
@Acephalia
Acephalia / wcritur.php
Last active December 3, 2023 22:12
Remove Inventory Tab For Shop Manager User Role
// Remove inventory capabilities for shop manager by u/acephaliax
add_filter('woocommerce_product_data_tabs', 'remove_inventory_tab', 10, 1);
// Add action to include inline CSS for shop_manager
add_action('admin_enqueue_scripts', 'inline_custom_admin_styles');
function remove_inventory_tab($tabs) {
global $post, $product_object;
// Check if the current user has the "shop_manager" role
@Acephalia
Acephalia / wcdapbos.php
Last active November 24, 2023 07:36
Woocommerce Dynamically adjust price for a specific product based on sales
// Dynamically adjust price for woocommerce product based on sales by u/acehaliax
add_filter('woocommerce_product_get_price', 'adjust_product_price', 10, 2);
function adjust_product_price($price, $product) {
$target_product_id = 827; // Target product ID
// Check if the current product matches the target product
if ($product->get_id() === $target_product_id) {
// Get the quantity sold for the product using get_total_sales()
$quantity_sold = $product->get_total_sales();
@Acephalia
Acephalia / wcapbospid.php
Created November 23, 2023 06:31
Adjust price based on order quantity for specific product ID
// Adjust price based on order quantity for specific product ID by u/acephaliax
function adjust_product_price_based_on_quantity( $cart ) {
if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return;
}
// Target product ID
$target_product_id = 828;
// Get the quantity of the targeted product in the cart
@Acephalia
Acephalia / wcpdl.php
Last active October 1, 2023 22:12
WC Product Dropdown List
//Product Dropdown Form by u/acephaliax
//This snippet will add a shortcode [[product-dropdown] that can be used to display a list of store products in a dropdown form. On submission the product will be added to cart and directed to the cart page.
//Use CSS selectors to style form as needed.
// Add shortcode for the product dropdown form
function product_dropdown_shortcode() {
ob_start();
?>
<div class="product-dropdown-container">
<form action="" method="POST" class="product-dropdown-form">
@Acephalia
Acephalia / wpdivrp.php
Last active September 11, 2023 23:57
Divi Remove Projects
//Remove Divi Projects Post Type
add_action( 'init', 'remove_divi_project_post_type' );
if ( ! function_exists( 'remove_divi_project_post_type' ) ) {
function remove_divi_project_post_type(){
unregister_post_type( 'project' );
unregister_taxonomy( 'project_category' );
unregister_taxonomy( 'project_tag' );
}