Persian WooCommerce SMS Shortcode

Below, you’ll find a detailed guide on how to add the Persian WooCommerce SMS Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the افزونه پیامک ووکامرس Persian WooCommerce SMS Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the افزونه پیامک ووکامرس Persian WooCommerce SMS Plugin and the shortcodes it provides:

Plugin Icon
افزونه پیامک ووکامرس Persian WooCommerce SMS

"Persian WooCommerce SMS is a plugin designed to integrate SMS functionalities into your WooCommerce store. It allows Persian users to send and receive text messages concerning their WooCommerce activities."

★★★★✩ (82) Active Installs: 30000+ Tested with: 6.2.3 PHP Version: 7.2
Included Shortcodes:
  • [PWooSMS_Shortcode]

Persian WooCommerce SMS [PWooSMS_Shortcode] Shortcode

The Persian Woocommerce SMS plugin shortcode is designed to enable SMS notifications for WooCommerce products. It displays a form where users can subscribe to product updates. The form includes options to select notification groups and input mobile numbers. It also checks if notifications are enabled and if the user is logged in. If conditions are met, a subscription can be made.

Shortcode: [PWooSMS_Shortcode]

Examples and Usage

Basic example: – The shortcode below can be used to display a form for a specific product. The product ID must be provided as the parameter.

[PWooSMS_Shortcode product_id=123 /]

PHP Function Code

In case you have difficulties debugging what causing issues with [PWooSMS_Shortcode] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( PWooSMS_Shortcode( true, true ), [ $this, 'displayForm' ] );

Shortcode PHP function:

function displayForm( $product = '' ) {

		if ( ! $this->enable_notification ) {
			return;
		}

		$product_id = PWooSMS()->ProductId( $product );
		if ( ! is_product() || empty( $product_id ) ) {
			return;
		}

		$product = wc_get_product( $product_id );

		$groups = $this->getGroups( $product_id );
		if ( empty( $groups ) ) {
			return;
		}

		do_action( 'pwoosms_before_product_newsletter_form', $product );

		$id = ++ self::$form_id;

		$can_be_subscribe = ! PWooSMS()->hasNotifCond( 'notif_only_loggedin', $product_id ) || is_user_logged_in();

		$disabled = '';
		if ( ! $can_be_subscribe ) {
			$disabled = 'disabled="disabled"';
		}

		?>

        <form class="sms-notif-form" id="sms-notif-form-<?php echo intval( $id ); ?>" method="post">
            <div style="display:none !important;width:0 !important;height:0 !important;">
                <img style="width:16px;display:inline;"
                     src="<?php echo PWOOSMS_URL; ?>/assets/images/tick.png"/>
                <img style="width:16px;display:inline;"
                     src="<?php echo PWOOSMS_URL; ?>/assets/images/false.png"/>
                <img style="width:16px;display:inline;"
                     src="<?php echo PWOOSMS_URL; ?>/assets/images/ajax-loader.gif"/>
            </div>

            <div class="sms-notif-enable-p" id="sms-notif-enable-p-<?php echo intval( $id ); ?>">
                <label id="sms-notif-enable-label-<?php echo intval( $id ); ?>" class="sms-notif-enable-label"
                       for="sms-notif-enable-<?php echo intval( $id ); ?>">
                    <input type="checkbox" id="sms-notif-enable-<?php echo intval( $id ); ?>" class="sms-notif-enable"
                           name="sms_notif_enable"
                           value="1">
                    <strong><?php echo PWooSMS()->getValue( 'notif_title', $product_id ); ?></strong>
                </label>
            </div>

            <div class="sms-notif-content" id="sms-notif-content">
				<?php foreach ( $groups as $code => $text ) : ?>
                    <!--<p id="sms-notif-groups-p-<?php /*echo $code . '_' . $id; */ ?>" class="sms-notif-groups-p">-->
                    <label class="sms-notif-groups-label sms-notif-groups-label-<?php echo esc_attr( $code ); ?>"
                           for="sms-notif-groups-<?php echo esc_attr( $code . '_' . $id ); ?>">
                        <input type="checkbox"
                               id="sms-notif-groups-<?php echo esc_attr( $code . '_' . $id ); ?>" <?php echo esc_attr( $disabled ); ?>
                               class="sms-notif-groups" name="sms_notif_groups[]"
                               value="<?php echo esc_attr( $code ); ?>"/>
						<?php echo esc_html( $text ); ?>
                    </label><br>
                    <!--</p>-->
				<?php endforeach; ?>

                <div class="sms-notif-mobile-div">
                    <input type="text" id="sms-notif-mobile-<?php echo intval( $id ); ?>" class="sms-notif-mobile"
                           name="sms_notif_mobile"
                           value="<?php echo get_user_meta( get_current_user_id(), PWooSMS()->buyerMobileMeta(), true ); ?>"
                           style="text-align: left; direction: ltr" <?php echo esc_attr( $disabled ); ?>
                           title="شماره موبایل" placeholder="شماره موبایل"/>
                </div>

				<?php if ( ! $can_be_subscribe ) : ?>
                    <p id="sms-notif-disabled-<?php echo intval( $id ); ?>" class="sms-notif-disabled">
						<?php echo PWooSMS()->getValue( 'notif_only_loggedin_text', $product_id ); ?>
                    </p>
				<?php else : ?>
                    <button id="sms-notif-submit-<?php echo intval( $id ); ?>"
                            class="sms-notif-submit single_add_to_cart_button button alt"
                            style="margin-top: 5px;"
                            type="submit">ثبت
                    </button>
				<?php endif; ?>

                <p id="sms-notif-result-p-<?php echo intval( $id ); ?>" class="sms-notif-result-p">
                    <span id="sms-notif-result-<?php echo intval( $id ); ?>" class="sms-notif-result"></span>
                </p>
            </div>
        </form>

		<?php
		do_action( 'pwoosms_after_product_newsletter_form', $product );

		if ( $id == 1 ) {
			wc_enqueue_js( '
			jQuery(document).ready(function($){
				$(".sms-notif-content").hide();
			    $(document.body).on( "change", ".sms-notif-enable", function() {
					if( $(this).is(":checked") )
						$(this).closest("form").find(".sms-notif-content").fadeIn();			
					else
				    	$(this).closest("form").find(".sms-notif-content").fadeOut();
				}).on( "click", ".sms-notif-submit", function() {
				    var form = $(this).closest("form");
				    var result = form.find(".sms-notif-result");
				    result.html( "<img style=\"width:16px;display:inline;\" src=\"' . PWOOSMS_URL . '/assets/images/ajax-loader.gif\" />" );
			    	var sms_group = [];
				    form.find(".sms-notif-groups:checked").each(function(i){
					    sms_group[i] = $(this).val();
			    	});
				    $.ajax({
					    url : "' . admin_url( "admin-ajax.php" ) . '",
				    	type : "post",
					    data : {
						    action : "wc_sms_save_notification_data",
					    	security: "' . wp_create_nonce( "wc_sms_save_notification_data" ) . '",
						    sms_mobile : form.find(".sms-notif-mobile").val(),
						    sms_group : sms_group,
						    product_id : "' . $product_id . '",
					    },
				    	success : function( response ) {
					    	result.html( response );
					    }
			    	});
				    return false;
		    	});
		    });
		' );
		}
	}

Code file location:

persian-woocommerce-sms/persian-woocommerce-sms/includes/class-subscription.php

Conclusion

Now that you’ve learned how to embed the افزونه پیامک ووکامرس Persian WooCommerce SMS Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *