Skip to content

Instantly share code, notes, and snippets.

@bporcelli
bporcelli / dokan-custom-settings-tab.php
Last active October 23, 2023 15:04
Adding a custom settings tab to the Dokan vendor dashboard
<?php
/**
* NOTE: This code example uses the generic vendor prefix 'prefix_' and omits text domains where
* the WordPress internationalization functions are used. You should replace 'prefix_' with your
* own prefix and insert your text domain where appropriate when incorporating this code into your
* plugin or theme.
*/
/**
@bporcelli
bporcelli / disable-marketship-shipping-methods.php
Created May 23, 2019 20:34
Disable MarketShip shipping methods
<?php
/**
* Disables the Flat Rate and Free Shipping shipping methods provided by MarketShip.
*
* @param array $methods MarketShip shipping methods.
*
* @return array
*/
function disable_marketship_shipping_methods( $methods ) {
@bporcelli
bporcelli / sst-force-tax-calculation.php
Last active September 16, 2019 13:05
Force Simple Sales Tax to calculate and display taxes on the cart page
<?php
/**
* Forces Simple Sales Tax to calculate and display taxes on the cart page.
*
* @return bool
*/
function sst_force_tax_display() {
return is_cart() || is_checkout();
}
@bporcelli
bporcelli / multiple-packages-shipping.php
Created September 17, 2019 21:57
Multiple Packages for WooCommerce, patched to eliminate conflict with Simple Sales Tax
<?php
/**
* Plugin Name: Multiple Packages for WooCommerce
* Plugin URI: http://www.bolderelements.net/multiple-packages-woocommerce/
* Description: A simple UI to take advatage of multiple shipping packages without PHP knowledge
* Author: Erica Dion
* Author URI: http://www.bolderelements.net/
* Version: 1.0.2
* WC requires at least: 2.6.0
* WC tested up to: 3.3.0
@bporcelli
bporcelli / sst-set-composite-product-price.php
Created October 18, 2019 15:22
Simple Sales Tax: Charge tax on composite products
<?php
/**
* Sets the taxable price for all Composite Products to the product price.
* This overrides the default behavior of Simple Sales Tax, which is to tax
* the components of a Composite Product and not the product itself.
*
* This hook MUST run with priority 11 or later to work properly.
*
* @see SST_Composite_Products::filter_composite_product_price()
@bporcelli
bporcelli / fix-ms-admin-calc.php
Created June 27, 2020 13:42
Fix for MarketShip admin shipping calculations issue
add_filter( 'woocommerce_cart_shipping_packages', function( $packages ) {
foreach ( $packages as $key => $package ) {
$is_admin_package = $package['seller_id'] && user_can( $package['seller_id'], 'manage_options' );
if ( $is_admin_package ) {
// Allow shipping via any shipping method
$packages[ $key ]['ship_via'] = array();
}
}
return $packages;
}, 30 );
@bporcelli
bporcelli / add-my-store-menu-item.php
Created July 18, 2020 17:02
Shows how to add a "My Store" menu item linking to the current user's Dokan store
<?php
/**
* Adds support for adding a "My Store" link to a WP nav menu.
*
* This works by finding all menu items with the URL "#dokan-my-store" and
* replacing "#dokan-my-store" with the current user's storefront URL. If the
* current user is not a vendor or Dokan is not active these menu items will
* be hidden instead.
*
@bporcelli
bporcelli / change-lkr-currency-symbol.php
Created August 1, 2020 16:51
Shows how to change the currency symbol for LKR in WooCommerce
<?php
/**
* Change the currency symbol for LKR to Rs.
*
* @param array $symbols Array of registered currency symbols.
*
* @return array
*/
function pp_change_lkr_currency_symbol( $symbols ) {
@bporcelli
bporcelli / hide-trs-dokan-policy-fields.php
Last active August 26, 2020 11:56
Snippet to hide the Dokan Shipping and Return Policy fields displayed by the Table Rate Shipping plugin. To use, simply copy and paste into your theme's functions.php file.
add_filter( 'trs_show_dokan_policy_fields', '__return_false' );
@bporcelli
bporcelli / trs-change-free-shipping-label.php
Last active October 16, 2020 02:14
Change the label the Plugin Pros Table Rate Shipping plugin uses for free shipping.
<?php
/**
* Changes the label Table Rate Shipping uses for free shipping.
* Replace NEW_FREE_SHIPPING_LABEL with the label you want to use
* for free shipping.
*
* @param string $label Shipping method label.
* @param WC_Shipping_Rate $method Shipping method rate data.
*