One Time Access URL after purchasing subscription

A simple solution would be creating a unique token upon purchasing a subscription/product. Save to token somewhere in database. Present the URL to the app passing the token as a GET variable. For eample, www.company.com/app/the-awesome-tool/?token=jvp2HBst5V7iHQeE2twq When accessed, check is the token is there at the database, if not restrict access. Delete the token from database … Read more

Display “Add to basket” and “Read more” buttons in the products shop page with woocommerce

Would something like this achieve what you are after? Could be refined more by using the default read more function rather than echoing it. function add_extra_read_more_btn() { global $product; if ($product->is_purchasable()) { echo ‘<div class=”woocommerce-LoopProduct-buttons-container”>’; echo ‘<a class=”button product_type_simple” href=”‘.get_permalink($product->ID).'”>Read more</a>’; } } add_action( ‘woocommerce_after_shop_loop_item’, ‘add_extra_read_more_btn’, 9 ); function close_extra_read_more_btn_wrap() { global $product; if ($product->is_purchasable()) … Read more

Adapt shipping surcharge code [closed]

Here’s an untested modified version of your code: function woocommerce_bt_postcode_surcharge() { global $woocommerce; if ( is_admin() && ! defined( ‘DOING_AJAX’ ) ) return; if ( $woocommerce->customer->get_shipping_country() === ‘GB’ ) { $postcode = $woocommerce->customer->get_shipping_postcode(); if ( isset( $postcode ) && strtoupper( substr( trim( $postcode ), 0, 2 ) ) === ‘BT’ ) { $woocommerce->cart->add_fee( ‘Surcharge’, 35, … Read more

Woocommerce – Hide shipping at all, if only certain product or products with certain shipping class is in the cart

Solved it. Just remeber to add the same shipping class to all variations too. add_filter( ‘woocommerce_package_rates’, ‘custom_shipping_rates’, 100, 2 ); function custom_shipping_rates( $rates, $package ) { $shipping_class = 506; // HERE set the shipping class ID $found = false; $productsincart = count($package[‘contents’]); foreach( $package[‘contents’] as $cart_item ) { if ($productsincart == 1 && $cart_item[‘data’];->get_shipping_class_id() == … Read more

wc_get_product_id_by_sku() returns 0 for products added programatically via update_post_meta

The problem was that I didn’t create product with WC_Product object. When I create product with this object it works. for instance $product = new WC_Product; $product->set_name(“my product”); $product->set_sku(“345678”); $product->save(); Then I can easity get the ID of the product by SKU $post_id = wc_get_product_id_by_sku(‘345678’);

Show menu order field in quick edit

The below code will help others to achieve the above task. <?php add_action( ‘wp_ajax_update_menu_order’, ‘update_menu_order’ ); add_action( ‘wp_ajax_nopriv_update_menu_order’, ‘update_menu_order’ ); function update_menu_order() { global $wpdb; $table_name = $wpdb->prefix.”posts”; $menu_order = $_POST[‘menu_order’]; $data = $_POST[‘post_id’]; $post_id = substr($data, strpos($data, “-“) + 1); $result = $wpdb->query($wpdb->prepare(“UPDATE $table_name SET menu_order=”$menu_order” WHERE ID=$post_id”)); echo $result; wp_die(); // this is … Read more