Skip to content

Instantly share code, notes, and snippets.

View woogist's full-sized avatar

WooCommerce.com Documentation woogist

View GitHub Profile
$args = array(
// Enter the ID (post ID) of the plan to grant access to
'plan_id' => 253,
'user_id' => $user_id,
);
wc_memberships_create_user_membership( $args );
add_filter( 'updated_users_subscriptions_for_order', 'wc_subs_suspend_on_cod' );
function wc_subs_suspend_on_cod( $order ) {
if ( ! is_object( $order ) ) {
$order = new WC_Order( $order );
}
foreach ( WC_Subscriptions_Order::get_recurring_items( $order ) as $order_item ) {
$subscription_key = WC_Subscriptions_Manager::get_subscription_key( $order->id, WC_Subscriptions_Order::get_items_product_id( $order_item ) );
// Get current user ID
$user_id = get_current_user_id();
// Check if the user is member of the plan 'gold'
if ( wc_memberships_is_user_active_member( $user_id, 'gold' ) ) {
echo 'This is a special message only for Gold members!';
} else {
echo 'I\'m sorry, you are not a gold member. There's nothing here for you!';
}
// Enable WP_DEBUG mode
define('WP_DEBUG', true);
// Enable Debug logging to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);
// Disable display of errors and warnings
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors',0);
// remove a column
function wc_csv_export_remove_column( $column_headers ) {
// the list of column keys can be found in class-wc-customer-order-csv-export-generator.php
unset( $column_headers['coupon_items'] );
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' );
// remove a column
function wc_csv_export_remove_column( $column_headers ) {
// the list of column keys can be found in class-wc-customer-order-csv-export-generator.php
unset( $column_headers['coupon_items'] );
return $column_headers;
}
add_filter( 'wc_customer_order_csv_export_order_headers', 'wc_csv_export_remove_column' );
/**
* Changes the redirect URL for the Return To Shop button in the cart.
*
* @return string
*/
function wc_empty_cart_redirect_url() {
return $_SERVER['HTTP_REFERER'];
}
add_filter( 'woocommerce_return_to_shop_redirect', 'wc_empty_cart_redirect_url' );
/**
* Print the product's vendor name before the product title in the loop.
*
* @return void
*/
function wc_vendors_name_loop() {
$vendors = get_the_terms( get_the_ID(), 'shop_vendor' );
if ( $vendors && ! is_wp_error( $vendors ) ) {
foreach ( $vendors as $vendor ) {
function custom_tracking_code() {
if ( is_product() ) {
?> Add your Product code here <?php
} elseif ( is_cart() ) {
?> Add your Cart code here <?php
} elseif ( is_order_received_page() ) {
?> Add your Thank you code here <?php
}
}
add_action( 'wp_head', 'custom_tracking_code' );
@woogist
woogist / wc_shipment_tracking_add_custom_provider.php
Last active September 22, 2022 02:37
Shipment Tracking: adds custom provider
/**
* wc_shipment_tracking_add_custom_provider
*
* Adds custom provider to shipment tracking or add existing providers to another country.
*
* Change the country name, the provider name, and the URL (it must include the %1$s)
* Add one provider per line
*/
add_filter( 'wc_shipment_tracking_get_providers' , 'wc_shipment_tracking_add_custom_provider' );