In WooCommerce, is there a way to set a flat rate on a specific type of product? [closed]

One of my clients is trying to do some weird things with shipping.

He wants to calculate a flat rate of $ 4 for a quantity of 5 widgets or fewer, and then add $ 1.50 per block of 5 widgets (ie, if someone orders 8, it should charge $ 5.50, or if the quantity is 12, then $ 7). This is only for one type of product, though, but he’s got multiple items of that product type, entered in as separate products.

I know, it’s a mess.

Is there any way to do this with shipping zones or something similar?

How Can I Append Inline Style to Post Images in WordPress

Simple problem, not sure where to start.

Posts on our website get pulled into an RSS feed and get automatically emailed by an email service. This works perfectly great, except for one thing — normal web size images make our emailed posts look bad on mobile — the images render too big and make the email too wide, such that the text reduces to a smaller size.

I need to add an inline style to uploaded post images:

style="max-width: 100px; max-height: auto;" 

This forces any image to be restricted to the width of the div into which we put the content.

I don’t care if the style tag gets added to the images in the post on the website or in the RSS feed, but it needs to be there or it ruins the emailed post on mobile. When I add the style inline myself, it causes the email look great in a mobile display.

Any thoughts on how I can inject this inline style?

use my custom code in woocommerce product image

I want to use my custom code in woocommerce products gallery image , I have done that before for a simple gallery but this time my code is little more professional and i want use the tag in woocommerce products gallery , here is the code:

<div class="product-gallery">                             <span class="badge">Offer</span>                             <div class="product-carousel owl-carousel">                                 <div class="item">                                     <a class="gallery-item" href="./assets/img/single-product/thumbnail-1.jpg"                                         data-fancybox="gallery1" data-hash="one">                                         <img src="./assets/img/single-product/thumbnail-1.jpg" alt="Product">                                     </a>                                 </div>                                 <div class="item">                                     <a class="gallery-item" href="./assets/img/single-product/thumbnail-2.jpg"                                         data-fancybox="gallery1" data-hash="two">                                         <img src="./assets/img/single-product/thumbnail-2.jpg" alt="Product">                                     </a>                                 </div>                                 <div class="item">                                     <a class="gallery-item" href="./assets/img/single-product/thumbnail-3.jpg"                                         data-fancybox="gallery1" data-hash="three">                                         <img src="./assets/img/single-product/thumbnail-3.jpg" alt="Product">                                     </a>                                 </div>                                 <div class="item">                                     <a class="gallery-item" href="./assets/img/single-product/thumbnail-4.jpg"                                         data-fancybox="gallery1" data-hash="four">                                         <img src="./assets/img/single-product/thumbnail-4.jpg" alt="Product">                                     </a>                                 </div>                             </div>                             <ul class="product-thumbnails">                                 <li class="active">                                     <a href="#one">                                         <img src="./assets/img/single-product/thumbnail-1.jpg" alt="Product">                                     </a>                                 </li>                                 <li>                                     <a href="#two">                                         <img src="./assets/img/single-product/thumbnail-2.jpg" alt="Product">                                     </a>                                 </li>                                 <li>                                     <a href="#three">                                         <img src="./assets/img/single-product/thumbnail-3.jpg" alt="Product">                                     </a>                                 </li>                                 <li>                                     <a href="#four">                                         <img src="./assets/img/single-product/thumbnail-4.jpg" alt="Product">                                     </a>                                 </li>                                 <li>                                     <a class="navi-link text-sm" href="./assets/video/download.mp4" data-fancybox                                         data-width="960" data-height="640">                                         <i class="mdi mdi-video text-lg d-block mb-1"></i>                                     </a>                                 </li>                             </ul>                         </div> 

OOP: Instantiate plugin, passing parameters and accessing super class properties from sub class object

I would like to know the "best" – OOP-way – and WP-compatible – format for instantiating an object, while passing arguments ( which are defined as properties in the parent class ) – which are then cleanly and correctly available to all sub classes, which extend the parent.

I would like to know how to make $ this->slug ( the parent prop ) available cleanly within the sub class, without having to pass the arguments to this class constructor.

The example code concept below works, but something smells wrong:

<?php  // plugin.php  namespace Q\Plugin;  // If this file is called directly, Bulk! if ( ! defined( 'ABSPATH' ) ) {     return; }  // autoloader ## require_once __DIR__ . '/autoload.php';  // Define Class ## class Plugin {      // class properties ##     protected $  slug     = false;      // construct ##     public function __construct( Array $  args = [] ) {          // set class props, if defined - check using null coalescing operator ##         $  this->slug     = $  args['slug'] ?? false ;      }      // public init callback ##     public function init() {          // setup CPT ##         $  cpt = new \Q\Plugin\CPT([             'slug'      => $  this->slug,         ]);         $  cpt->init();      }  }  // instantiate the plugin class and make the returned object available as a (optional) global variable  ## global $  q_plugin; $  q_plugin = new Plugin([     'slug'      => 'q_cpt', // cpt slug -- singular ## ]); $  q_plugin->init();  // NAMESPACE/cpt.php  namespace Q\Plugin\CPT;  class CPT extends \Q\Plugin {      // construct ##     public function __construct( Array $  args = [] ) {          // store passed args ##         $  this->args = $  args;      }      // public init callback ##     public function init() {          // sanity ##         if(              ! isset( $  this->args['slug'] )          ){              error_log( 'Error in params passed to '.__CLASS__ );              return false;          }          // $  this->args['slug'] is now available to use in register_post_type function         // BUT, I would like to know how to make $  this->slug ( the parent prop ) available cleanly, without having to pass the arguments to this class constructor      }  } 

Thanks!

how to send user email confirmation without register the user

I want the new user on resgistration to receive a confirmation email, and only after confirm the email can get access to the login area, not before.

I had made a custom form, a new table to store the info, send the email of validation, in the meanwhile the user is only with his info on a custom table on the database, only after the email validation, this means the user click the custom email link and a new window is open on the website congratulating him for the new registration and email validation, and the user gets registrated, already log on and goes to the home page. in the backend wordpress validates the key generated and returned by the user, regist the user and delete the info from the custom email confirmation table. ok, this is all done and working fine. eheh.

My question is is there any wordpress function to do the same, because I dont know any.

Display images that are not in the content

The function below returns all the images attached to the post, however, if I delete the image inserted into the content, it still returns in the function, because the media is still as attached to the post.

So, how do I really bring only the images inserted in the content of the post?

<?php  $  args = array(         'post_type'   => 'attachment',         'posts_per_page' => -1,         'post_mime_type' => 'image',         'post_parent' => $  post->ID,     );      $  attachments = get_posts( $  args );      if ( $  attachments ) {          foreach ( $  attachments as $  attachment ) {              echo wp_get_attachment_image( $  attachment->ID, false );             echo '<hr>';             echo '<br>';          }     } ?> 

Adding Author URL to Nav Menu via Shortcode

I’m looking to add the Author URL to the Nav Menu via a shortcode.

Here’s the shortcode I registered:

add_shortcode( 'author_url', function() {     return get_author_posts_url( get_current_user_id() ); } ); 

After registering the shortcode, I tried using this plugin to add it to the nav menu: https://wordpress.org/plugins/shortcode-in-menus/

However, the shortcode output is https//mysite.local on my localhost

Notice how it’s lacking the ‘:’ after the https.

What’s going on, and how can I fix this?

Thanks!

Woocommerce Filter Products by Price widget – filter by price in custom field

I have products with price per package in eshop. I also created custom field with product price per square meters. Products are sold only by package not by square meters, but on archive page I need filtering products by price per square meters. I unregistered WC_Widget_Price_Filter widget and registered modified version of that widget, which displays correct min and max prices in square meters in filter slider. I modified function price_filter_post_clauses to display correct products. Function is located in includes/class-wc-query.php.

public function price_filter_post_clauses( $  args, $  wp_query ) {     global $  wpdb;      // phpcs:ignore WordPress.Security.NonceVerification.Recommended     if ( ! $  wp_query->is_main_query() || ( ! isset( $  _GET['max_price'] ) && ! isset( $  _GET['min_price'] ) ) ) {         return $  args;     }      // phpcs:disable WordPress.Security.NonceVerification.Recommended     $  current_min_price = isset( $  _GET['min_price'] ) ? floatval( wp_unslash( $  _GET['min_price'] ) ) : 0;     $  current_max_price = isset( $  _GET['max_price'] ) ? floatval( wp_unslash( $  _GET['max_price'] ) ) : PHP_INT_MAX;     // phpcs:enable WordPress.Security.NonceVerification.Recommended      /**      * Adjust if the store taxes are not displayed how they are stored.      * Kicks in when prices excluding tax are displayed including tax.      */     if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {         $  tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.         $  tax_rates = WC_Tax::get_rates( $  tax_class );          if ( $  tax_rates ) {             $  current_min_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_min_price, $  tax_rates ) );             $  current_max_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $  current_max_price, $  tax_rates ) );         }     }      $  args['join']   = $  this->append_product_sorting_table_join( $  args['join'] );     $  args['where'] .= $  wpdb->prepare(         ' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',         $  current_min_price,         $  current_max_price     );     return $  args; } 

I modified sql in $ args[‘join’] and $ args[‘where’]. Is it possible to modify this function without modifying it directly?

Getting meta in editor plugin, and event triggering issue

I have a Custom Post Type defined with custom-fields support. I then registered a meta field.

The first issue is that select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles always returns undefined on first call (before being updated by dispatch( 'core/editor' ).editPost). Also, when I save the Custom post Type the value isn’t modified in the database.

The other issue is, when check any of the checkboxes, on first click, isChecked() is properly called, on next clicks it doesn’t happen, but updateMeta() is triggered. If I fold/unfold the control or uncheck a checkbox, all the checkboxes do get updated by calling isChecked():

animation example of second issue

Here is my code:

class Metaboxes extends Base {      /**      * Setup user.      */     public function setup() {         add_action('init', [$  this, 'init'] );     }      public function init () {         register_post_meta(             'vaenc_actu',             '_vaenc_actu_roles_scope_roles',             [                 'show_in_rest' => true,                 'single'       => true,                 'type'         => 'array',                 'default'       => [],                 'auth_callback' => function() {                     return current_user_can( 'edit_posts' );                 }             ]         );     } } 

My javascript is like so:

const {registerPlugin}                              = wp.plugins; const {PluginDocumentSettingPanel}                  = wp.editPost; const {PanelBody, CheckboxControl}                  = wp.components; const {useSelect, select, withSelect, withDispatch} = wp.data; const {Fragment, useState}                          = wp.element; const {__}                                          = wp.i18n; const {compose}                                     = wp.compose;  const RolesControl = ( {isChecked, updateMeta} ) => {     return (         <>             <Fragment intialOpen={true}>                 <CheckboxControl                     label={__( "PRI", "vae" )}                     checked={isChecked( 'vae-pri' )}                     onChange={( value ) => updateMeta( 'vae-pri', value )}                 />                 <CheckboxControl                     label={__( "PRC", "vae" )}                     checked={isChecked( 'vae-prc' )}                     onChange={( value ) => updateMeta( 'vae-prc', value )}                 />                 <CheckboxControl                     label={__( "Certificateurs", "vae" )}                     checked={isChecked( 'vae-certif' )}                     onChange={( value ) => updateMeta( 'vae-certif', value )}                 />             </Fragment>         </>     ) }  const RolesField = compose( [     withSelect( () => {         return {             actu_scope_meta: select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles,         };     } ),     withDispatch( ( dispatch ) => ({         isChecked ( prop ) {             let meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles;             if ( meta ) {                 return meta.includes( prop );             }             return false         },         updateMeta ( prop, value ) {             let meta = select( 'core/editor' ).getEditedPostAttribute( 'meta' )._vaenc_actu_roles_scope_roles;             if ( !meta ) meta = []              if ( meta.includes( prop ) && !value ) {                 meta = meta.filter( arrayItem => arrayItem !== prop );             } else if ( !meta.includes( prop ) ) {                 meta.push( prop );             }              dispatch( 'core/editor' ).editPost( {meta: {_vaenc_actu_roles_scope_roles: meta}} );         },     }) ), ] )( RolesControl );  const Render = () => {     const postType = useSelect( select => select( 'core/editor' ).getCurrentPostType() );     if ( 'vaenc_actu' !== postType ) {         return null;     }      return (         <>             <PluginDocumentSettingPanel                 name="vae-role-scope-sidebar"                 title={__( 'Restrictions', 'vae' )}             >                 <RolesField/>             </PluginDocumentSettingPanel>         </>     ) }  registerPlugin( 'vae-role-scope-sidebar', {     render: Render } )  

Upload Gravity Form files to OneDrive [closed]

I’ve been looking for an away of upload files from Gravity Form direct to the cloud on OneDrive. And so far, I found some codes that could be useful:

 add_filter( 'gform_upload_path', function ( $  path_info, $  form_id ) {         GFCommon::log_debug( "log_upload_path(): path_info for form #{$  form_id} => " . print_r( $  path_info, true ) );               return $  path_info;     }, 1, 2 );       add_filter( 'gform_upload_path', 'change_upload_path', 10, 2 ); function change_upload_path( $  path_info, $  form_id ) {    $  path_info['path'] = '/home/public_html/yourdomainfolder/new/path/';    $  path_info['url'] = 'http://yourdomainhere.com/new/path/';    return $  path_info; }    <?php require_once 'functions.inc.php'; $  token = skydrive_tokenstore::acquire_token(); // Call this function to grab a current access_token, or false if none is available.  if (!$  token) { // If no token, prompt to login. Call skydrive_auth::build_oauth_url() to get the redirect URL.        echo "<div>";        echo "<img src='statics/key-icon.png'>&nbsp";        echo "<a href='" . skydrive_auth::build_oauth_url() . "'>Login with SkyDrive</a></span>";        echo "</div>"; } else {        $  sd = new skydrive($  token);        try {            $  response = $  sd->put_file($  _GET['folderid'], '/file/to/put');            // File was uploaded, return metadata.            print_r($  response);        } catch (Exception $  e) {            // An error occured, print HTTP status code and description.            echo "Error: ".$  e->getMessage();            exit;        } } 

Source: https://docs.gravityforms.com/gform_upload_path/
https://stackoverrun.com/fr/q/8253794

Instead of my domain path I would like to point it to one folder on Onedrive and if possible, generate a new folder for each upload containing the current WooCommerce order number. I don’t have much experience with PHP so any useful help will be great!