Changing Woocommerce flat rate every nth number of items

To change “Flat rate” shipping cost based on cart items quantity count that belongs to a specific shipping class, you will need something a bit different: add_filter( ‘woocommerce_package_rates’, ‘progressive_shipping_cost_based_shipping_class_quantity_steps’, 10, 2 ); function progressive_shipping_cost_based_shipping_class_quantity_steps( $rates, $package ) { // HERE Bellow your settings $shipping_class = “large-shipping”; // The shipping class ID $qty_step = 3; // … Read more

Add the Name of Products Ordered to Admin New Order Email WooCommerce

Since Woocommerce 3 your actual code is a bit outdated. In the following you will get all products names (coma separated) in the email subject. add_filter(‘woocommerce_email_subject_new_order’, ‘change_admin_email_subject’, 10, 2); function change_admin_email_subject( $subject, $order ) { $products_names = array(); foreach ( $order->get_items() as $item ) { $products_names[] = $item->get_name(); } return sprintf( ‘[%s] New Customer Order … Read more

Unit Test in WordPress

Take a look at the WordPress core setup with PHPUnit: https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/ Using this process rather than rolling your own allows you to leverage the boostrapping (and other customization) specific for WordPress. From the Codex: When phpunit is invoked, the test suite runs a script that sets up a default installation of WordPress, with a configuration … Read more

the_title gives me the page’s title not the post title in the following code

You are using the default page loop and it will output the current page attributes like title or other. You should create your own loop with custon query instead. See WP_Query or get_posts. Example $query = new WP_Query(array( ‘post_type’ => ‘post’, ‘posta_status’ => ‘publish’, )); if($query->have_posts()){ while($query->have_posts()){ $query->the_post(); echo get_the_title(); } wp_reset_postdata(); }

Sending jsPDF documents to the server

Keep in mind not everyone is running JavaScript, so you really need a server-side form processor like PHP rather than relying solely on jQuery. Best thing to do on a WordPress site is create a plugin that processes your form. You can include helper libraries like FPDF to not only generate the PDFs but that … Read more

Custom admin page: How to save changes specific to users

Then save the data in the usermeta table, linked to each user, by update_user_meta() and get_user_meta() functions. get_current_user_id() gives you the $user_id to pass. Choose a $meta_key that wion’t create conflict, preferrably with a unique prefix. Same rule as for keys for saving data in options table.